我想在表1中创建一个检查特定值的选择查询(例如下面:'green'),如果存在,它在表2中找到相同的id并显示该行数据。
table 1
id car
1 black
2 green
table 2
id status
1 old
2 broken
所以结果应该是:'破碎'。
继承我的代码:
SELECT TOP 100 car CASE WHEN table1.car IN ('green') THEN Table2.status END AS 'result'
FROM Table1.ID INNER JOIN Table2.ID
答案 0 :(得分:4)
SELECT t1.car, t2.status AS result
FROM Table1 t1
INNER JOIN Table2 t2
ON t1.id = t2.id
WHERE t1.car = 'green'
答案 1 :(得分:1)
为什么这不仅仅是一个加入?
select c.id, c.car, s.status
from car c, status s
where c.id = s.id
and car = 'green' -- if desired
;