简体   繁体   中英

SQL Help for combining two queries

I want to combine these two SQL queries into one. Any idea on how do I do it?

Select A, B, C 
from table1 
where condition1


select D 
from table2 
where table1.B=table2.E 

(table2 has the mapping of column B of table1)

I just want to fetch A,B,C,D in a single select query. Any help would be appreciated.

INNER JOIN (read up on joins here http://www.w3schools.com/sql/sql_join.asp )

SELECT A, B, C, D
FROM table1 t1
INNER JOIN table2 t2 ON t1.B = t2.E
WHERE condition1

You could use a join :

select A, B, C, D
from table1 
left join table2
on table1.B = table2.E 
where condition1

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM