海友我对数据库查询有疑问 [英] Hai Friends I Have A Question On Database Query
本文介绍了海友我对数据库查询有疑问的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有三张桌子
喜欢
桌子
tlid mbno名称性别
tl1 123是m
table1
id tlid rfid
1 tl1 12
2 tl1
3 tl1
table2
rfid type abc xyz tlid
12 one a .. x .. tl1
i想要显示详细信息,例如
如何为此写一个查询你可以告诉我依赖于mbno
tlid id name性别类型abc xyz
tl1 1是m one a one .. x ..
tl1 2是m
tl1 3是m
i不想这样展示
tlid id name性别类型abc xyz
tl1 1是m one a .. x ..
tl1 1 yes m
tl1 2 yes m
tl1 3是m
解决方案
Tr y:
SELECT a.tlid,a.id,b.name,b.gender,c 。 type ,c.abc,c.xyz
FROM table1 a
< span class =code-keyword> JOIN [ table ] b ON a.tlid = b.tlid
LEFT JOIN table2 c ON a.rfid = c.rfid
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
)
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
解决方案
Try:
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
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
)
这篇关于海友我对数据库查询有疑问的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文