Use results from one sql query in another where statement (subquery?)

前端 未结 1 1286
無奈伤痛
無奈伤痛 2020-12-23 19:42

I see many similar questions but they\'re either so complex I can\'t understand them, or they don\'t seem to be asking the same thing.

It\'s simple: I have two colum

相关标签:
1条回答
  • 2020-12-23 20:15
    SELECT dfid,count(*) 
    from downloads_downloads 
    WHERE dmid IN (
        SELECT dmid 
        FROM downloads_downloads 
        where dfid = "7024"
    )
    group by dfid
    

    or using a self join

    select t1.dfid,count(*)
    from downloads_downloads t1
    inner join downloads_downloads t2
    on t1.dmid = t2.dmid
    where t2.dfid = "7024"
    

    if this takes too long then you will probably need to post an explain plan (google it!)

    0 讨论(0)
提交回复
热议问题