dpv21589 2011-06-12 12:30
浏览 71
已采纳

SQL SELECT问题

I am trying to perform a SQL query that acts in two parts.

First, I have a query that returns a list of 10 Ids. But then I want to have a SELECT statement which has a WHERE clause for each of these 10 ids.

Is this possible?

I tried:

    SELECT * FROM tablenameWHERE id= (SELECT id FROM table_of_ids WHERE 
    tableid='1a177de1-3f25c9b7910b' OR 
    tableid='64faecca-133af807a65a' OR
... up to 10 Ids)

but it returns with an error stating the subquery returns more than 1 row.

Note, the tableid and id columns of table_of_ids are different values.

Does anyone know how to accomplish this? I seem to be at a loss myself.

If it matters, I am using mySQL and PHP.

Cheers, Brett

  • 写回答

6条回答 默认 最新

  • dongzhuo2010 2011-06-12 12:32
    关注

    Not a very optimized query, but you could use IN instead of =

     SELECT * FROM tablename WHERE id IN (SELECT id FROM table_of_ids WHERE 
        tableid='1a177de1-3f25c9b7910b' OR 
        tableid='64faecca-133af807a65a' OR
    ... up to 10 Ids)
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(5条)

报告相同问题?