Click here to Skip to main content
15,895,799 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
in this query how can i get 2-3 columns?

but not use join or unıon

"SELECT A.*,(SELECT COL1,COL2,COL3 FROM EATTM001 WHERE COL2=A.COL2)  FROM SYS20.EATTM002 A "


What I have tried:

"SELECT A.*,(SELECT COL1 FROM EATTM001 WHERE COL2=A.COL2)  FROM SYS20.EATTM002 A "
Posted
Updated 7-Sep-20 10:33am
Comments
Sandeep Mewara 7-Sep-20 15:48pm    
Any specific reason on Why no join when you want data from two tables and they have a common column?
Member 14588284 7-Sep-20 16:07pm    
because maybe in second table there is no equal value in col2 first table col2 value

Sandeep Mewara 7-Sep-20 16:30pm    
That does not qualify for LEFT/RIGHT outer join?
Member 14588284 8-Sep-20 2:00am    
Thanks, İ didnt use it before :)

1 solution

Based on your comment, I propose you use LEFT OUTER JOIN:
The LEFT JOIN keyword returns all records from the left table (table1), and the matched records from the right table (table2). The result is NULL from the right side, if there is no match


Example:
SQL
SELECT EATTM002.*, EATTM001.*
FROM EATTM002
LEFT JOIN EATTM001 ON EATTM001.COL2 = EATTM002.COL2
All from EATTM002 and matching ones for EATTM001 will be retrieved.
 
Share this answer
 
v3
Comments
Member 14588284 8-Sep-20 2:01am    
Thanks, İ didnt use it before :)
Member 14588284 8-Sep-20 17:26pm    
Can i get sum of a column with left joın?
Sandeep Mewara 9-Sep-20 1:13am    
Yes. https://learnsql.com/blog/introduction-using-aggregate-functions-joins/

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900