作者cutekid (可爱小孩子)
看板Database
标题Re: [SQL ] left join(?)
时间Tue Jun 24 15:52:32 2014
select a,b
from (
select table1.id,table2.d as a -- 将 table1.a 替代成 table2.d
from table1 inner join table2
on table1.a = table2.c
) as t1
inner join (
select table1.id,table2.d as b -- 将 table1.b 替代成 table2.d
from table1 inner join table2
on table1.b = table2.c
) as t2
on t1.id = t2.id
where t1.id = 1
※ 引述《BigLoser (大鲁蛇)》之铭言:
: 资料库名称: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
: 小明 小华
: 请问该怎麽下,谢谢
--
※ 发信站: 批踢踢实业坊(ptt.cc), 来自: 210.61.233.210
※ 文章网址: http://webptt.com/cn.aspx?n=bbs/Database/M.1403596354.A.4F3.html
1F:推 BigLoser:请问一下,一定得用作种作法吗? 似乎效率不好? 06/24 17:04
2F:→ cutekid:#1JgI7Tby 中 scpisces 的作法比较好 06/25 08:39