在查询的where子句中更改select查询,以便在查询中只有一个select

时间:2013-12-03 14:04:00

标签: mysql sql select join

好的,我怎么能改变这个:

select * from quallev_qualificationlevel quallev
where quallev.quallev_qual_id in (/* */ select qual.qual_id from qual_qualification qual, qde_qualificationdescription qde
where (qual.qual_id = qde.qde_qual_id)
and qual.qual_startdate <= '2013-12-02'
and qual.qual_enddate >= '2013-12-02'
and qde.qde_namepurpose_cd_id = 7294
and qde.qde_langauge_id = 2
and qde.qde_startdate <= '2013-12-02'
and qde.qde_enddate >= '2013-12-02'
order by qual.qual_id,
        qual_code /* */)
and quallev.quallev_startdate <= '2013-12-02'
and quallev.quallev_enddate >= '2013-12-02'

只有一个选择?

我假设我需要使用某种形式的内部联接,只是不确定wt和如何

1 个答案:

答案 0 :(得分:1)

替换你的in条款,你可以做

inner join qual_qualification qual on qual.qual_id = quallev.quallev_qual_id
inner join qde_qualificationdescription qde on qual.qual_id = qde.qde_qual_id

但是inner joinin子句不同。 因此,您不应再使用select *,但至少select quallev.*

如果联接为每个qual_qualification检索的次数超过1 quallev_qualificationlevel,您将获得重复的结果,因此您可能需要distinct子句。