我有以下问题:我的目标是一次获得两行。它的两倍相同"选择"声明,只是另一个ID。用我的代码我得到第二行。如何同时获得两条线?
select
table1.attr1 + table2.attr2 as total,
table1.id
FROM table1, table2
WHERE table.id = 1 AND table2.id = 1;
select
table1.attr1 + table2.attr2 as total,
table1.id
FROM table1, table2
WHERE table.id = 2 AND table2.id = 2;
答案 0 :(得分:2)
将明确的joins
与on
子句一起使用:
select t1.attr1 + t2.attr2 as total
, t1.id
FROM table1 t1 join table2 t2 on t1.id = t2.id
WHERE t1.id in (1, 2)
答案 1 :(得分:1)
修改您的加入条件:
SELECT
table1.attr1 + table2.attr2 as total,
table1.id
FROM table1, table2
WHERE (table.id = 1 AND table2.id = 1)
OR (table.id = 2 AND table2.id = 2)