Click here to Skip to main content
15,867,308 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
i have three tables
like

table
tlid mbno name gender 
tl1   123   yes      m 


table1
id   tlid	 rfid
1     tl1	 12	
2     tl1       
3     tl1


table2
rfid   type  abc  xyz tlid
12     one    a..   x..   tl1



i want to show the details like

how to write a query for this can you please tell me depend on mbno
tlid  id  name gender type abc xyz
tl1    1    yes      m     one  a..  x..
tl1    2    yes      m 
tl1    3    yes      m 



idon't wanna show like this
tlid  id  name gender type abc xyz
tl1    1    yes      m     one  a..  x..
tl1    1    yes      m
tl1    2    yes      m 
tl1    3    yes      m
Posted
Updated 9-Apr-15 19:04pm
v4
Comments
Maciej Los 7-Apr-15 1:50am    
What have you done till now? Where are you stuck?

1 solution

Let the first table be table0, use multiple left join like this:
select t0.tlid, t1.id, t0.name, t0.gender, t2.type, t2.abc, t2.xyz from 
table0 t0 left join table1 t1 on t0.tlid =t1.tlid
left join table2 t2 on t1.rfid=t2.rfid

Learn more about Visual Representation of SQL Joins[^]
 
Share this answer
 
Comments
Parazival 10-Apr-15 1:08am    
executed table like bellow

tlid id name gender type abc xyz
tl1 1 yes m one a.. x..
tl1 1 yes m----this record should not show
tl1 2 yes m
tl1 3 yes m


thankxxxx
Peter Leow 10-Apr-15 1:23am    
Seeing is believing => http://sqlfiddle.com/#!6/26d74c/1

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