If I have table1 contains Name, col2, col3 and table2 contains Name, NickName and col6.
I want to do select statement such I have a table like:
Name, NickName, col2, col3
where if table1 has 3 rows the new table should have the same.
Updating to answer your question:
Try this:
WITH tbl2 AS (SELECT DISTINCT ON (Name) Name,Nickname FROM table2 ORDER BY Name)
SELECT tbl1.Name, tbl2.Nickname, tbl1.col2, tbl1.col3 FROM
table1 tbl1 INNER JOIN tbl2 ON tbl1.Name = tbl2.Name
Disclaimer: haven't tested this. Let me know if it works.
ON instead of WHERE? Also, Imagine you have 1 row in table1 and 4 rows in table2, so will get more than one row when the condition table1.Name = table2.Name is satisfied.