简体   繁体   中英

Left Join with where clause

I have 3 tables A, B and C

替代文字

I am doing this :- /* There is no relation between Table A and Table B . Table A is just used to provide values to C.Profile */ 1st step ) D <---- Select * from C where Profile=1 // want to give a specific ProID(I have successfully retrieved it from A table)

2nd Step ) Output <--- Select B.sname,D.Status from B Left Join D On B.ID=D.ID

so that the output looks like the required output table shown above:-

Can I do this by using a single query? how?

Do you mean a subquery:

Select B.DirName,D.Status 
from B Left Join (
    Select * 
    from C 
    where ProId=1) As D 
On B.DirID=D.DirID

It is best to use a list of fields rather than *

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