[SQL ] left join(?)

楼主: BigLoser (大鲁蛇)   2014-06-24 14:59:38
数据库名称:mssql
内容/问题描述:
table1 talbe2
id a b c d
1 01 02 01 小明
2 02 02 02 小华
希望可以一段sql指令可以
select table1.a, table1.b from table where id=1
得到结果
a b
小明 小华
请问该怎么下,谢谢
作者: scpisces (失败的勇气。)   2014-06-24 22:11:00
select t1.a,t1.bfrom table1 as t1left join table2 as t2 on t1.a=t2.cleft join table2 as t3 on t1.b=t3.cwhere t1.id=1我倾向用left join
作者: cutekid (可爱小孩子)   2014-06-25 08:36:00
推楼上(Y)修正第一行应为: select t2.d as a,t3.d as b#1JgI7Tby 中 scpisces 的作法比较好
楼主: BigLoser (大鲁蛇)   2014-06-25 09:58:00
楼上 你贴的那个就是我这篇的代码吧@@
作者: cutekid (可爱小孩子)   2014-06-25 10:10:00
哈哈,对对对。我原本要推在下篇,不小心推错篇了(逃)

Links booklink

Contact Us: admin [ a t ] ucptt.com