这可以在一个查询中完成吗?

时间:2011-01-31 17:20:28

标签: sql mysql

id (primary)
key1,key2,key3 (secondary)

给定id N

查询#1

select key1,key2,key3 from table where id=N  --  key1n,key2n,key3n

查询#2

select * from table where key1 = key1n and key2 = key2n  --  results...

1 个答案:

答案 0 :(得分:6)

SELECT  t2.*
FROM    table t1
JOIN    table t2
ON      t2.key1 = t1.key1
        AND t2.key2 = t1.key2
        AND t2.key3 = t1.key3
WHERE   t1.id = '$N'