我有2张桌子。
表1
+-------+-------------+------+-----+---------+----------------+
|Field | Type | Null | Key | Default | Extra |
+-------+-------------+------+-----+---------+----------------+
| Gene | varchar(15) | YES | | NULL | |
| G_Cor | varchar(15) | YES | | NULL | |
| OMID | varchar(10) | YES | | NULL | |
+-------+-------------+------+-----+---------+----------------+
表2:
+-------+-------------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+-------+-------------+------+-----+---------+----------------+
| Sym_A | varchar(15) | YES | | NULL | |
| Sym_B | varchar(15) | YES | | NULL | |
| Int_Ty| varchar(10) | YES | | NULL | |
+-------+-------------+------+-----+---------+----------------+
现在我从表2中检索Sym_A和Sym_B,它与表1中的Gene相同,我必须显示一个单独的表。
答案 0 :(得分:0)
我知道您需要一个查询来检索表2中具有
的行
Sym_A=Gene OR Sym_B=Gene
,因为你的问题不是那么清楚(如果你想让它们满足,只需更改AND的OR)
在这种情况下,以下查询将起作用:
SELECT t2.Sym_A, t2.Sym_B
FROM Table2 t2, Table1 t1
WHERE (t2.Sym_A=t1.Gene) OR (t2.Sym_B=t1.Gene);
答案 1 :(得分:0)
SELECT t2.`Sym_A`,t2.`Sym_B`
FROM table 2 t2
JOIN table t1 ON (t2.`Sym_A`=t1.`Gene`) OR (t2.`Sym_B`=t1.`Gene`);