我有两张像这样的表:
表gene_names
:
+------------------+------------------+
| gene_alias | gene_name |
+------------------+------------------+
| AC148152.3_FG007 | AC148152.3_FG007 |
| AC149829.2_FG002 | AC149829.2_FG002 |
| AC149829.2_FG004 | AC149829.2_FG004 |
| AC155352.2_FG009 | AC155352.2_FG009 |
| AC155352.2_FG012 | AC155352.2_FG012 |
+------------------+------------------+
另一个名为gene_transcripts
的表:
+-------------------+------------------+
| transcript_alias | gene_alias |
+-------------------+------------------+
| AC148152.3_FGT007 | AC148152.3_FG007 |
| AC149829.2_FGT002 | AC149829.2_FG002 |
| AC149829.2_FGT004 | AC149829.2_FG004 |
| AC155352.2_FGT009 | AC155352.2_FG009 |
| AC155352.2_FGT012 | AC155352.2_FG012 |
+-------------------+------------------+
我想要的是从gene_alias
获取gene_transcripts
和从gene_name
获取gene_names
。为此,我做(例子):
SELECT gene_transcripts.gene_alias,
gene_names.gene_name
FROM gene_transcripts,
gene_names
WHERE gene_transcripts.gene_alias="AT4G38300_oG.1"
AND gene_transcripts.gene_alias=gene_names.gene_alias;
它没有结果,因为gene_alias
“AT4G38300_oG.1”在表gene_names
中没有条目。到目前为止,它似乎非常合乎逻辑和合理。
我想得到什么(我不知道如何实现这个,因此我在这里问这个问题),是如何获得以下输出:
+-------------------+------------------+
| transcript_alias | gene_alias |
+-------------------+------------------+
| AT4G38300_oG.1 | NULL |
+-------------------+------------------+
这可能吗?
答案 0 :(得分:1)
只使用左连接
select
gt.gene_alias as transcript_alias,
gn.gene_name as gene_alias
from gene_transcripts gt
left join gene_names gn on gt.gene_alias=gn.gene_alias
where gt.gene_alias="AT4G38300_oG.1"
答案 1 :(得分:0)
SELECT gene_transcripts.gene_alias,
gene_names.gene_name
FROM gene_transcripts,
gene_names
WHERE (gene_transcripts.gene_alias="AT4G38300_oG.1"
AND gene_transcripts.gene_alias=gene_names.gene_alias)
OR gene_transcripts.gene_alias IS NULL;