Click here to Skip to main content
15,886,830 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 

i don'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 21:20pm
v2

Try:
SQL
SELECT a.tlid, a.id, b.name, b.gender, c.type, c.abc, c.xyz
FROM table1 a
JOIN [table] b ON a.tlid = b.tlid
LEFT JOIN table2 c ON a.rfid = c.rfid
 
Share this answer
 
v2
Comments
Parazival 10-Apr-15 4:14am    
sorry it will show only one record

tlid id name gender type abc xyz
tl1 1 yes m one a.. x..

thanks
OriginalGriff 10-Apr-15 4:40am    
Didn't notice your null values - answer updated.
SELECT table.tlid ,
table1.id ,
table.NAME ,
table.gender ,
table2.TYPE ,
table2.abc ,
table2.xyz
FROM table
LEFT JOIN table1 ON ( table.tlid = table1.tlid )
LEFT JOIN table2 ON ( table2.rfid = table1.rfid
AND table.tlid = table2.tlid
)
 
Share this answer
 
Comments
Parazival 10-Apr-15 23:08pm    
nice one but
same out put
tlid id name gender type abc xyz
tl1 1 yes m one a.. x..
tl1 1 yes m// i don't want this record
tl1 2 yes m
tl1 3 yes m


thankssss

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