我有3个表,即person,person2,person3。每个表格都包含两个字段name和phno。 如果我给一个特定的PHNO查询在每个表使用3个表检索单行
我想是这样的,以显示这个数字的存在:
select a.name as Name, a.phno,
case when a.phno then 'Y' else 'N' end as Phone_Number1,
case when b.phno then 'Y' else 'N' end as Phone_Number2,
case when c.phno then 'Y' else 'N' end as Phone_Number3
from person as a, person2 as b, person3 as c
where a.phno = '123456' and b.phno = '123456' and c.phno = '123456';
这个查询只能在所有表中包含的值对于特定PHNO ..
我需要出去放像
phno Phone_Number1 Phone_Number2 Phone_Number3
123456 Y Y Y
,如果它存在于所有的表
phno Phone_Number1 Phone_Number2 Phone_Number3
123456 N Y Y
如果它不存在,则 'N' 应在该特定表dispayed ..
这是行不通的。如果任何表中缺少该行,则联接不会返回任何内容,因为它是交叉产品。 – Barmar
尝试没有'where'? – jerdiggity
现在,您将获得数十亿行,因为您正在生成所有3个整个表的交叉产品。 – Barmar