Solution to “subquery returns more than 1 row” error

前端 未结 4 1709
囚心锁ツ
囚心锁ツ 2020-11-27 02:40

I have one query that returns multiple rows, and another query in which I want to set criteria to be either one of values from those multiple rows , so basicly I want the su

4条回答
  •  眼角桃花
    2020-11-27 03:27

    You can use in():

    select * 
    from table
    where id in (multiple row query)
    

    or use a join:

    select distinct t.* 
    from source_of_id_table s
    join table t on t.id = s.t_id
    where 
    

    The join is never a worse choice for performance, and depending on the exact situation and the database you're using, can give much better performance.

提交回复
热议问题