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条)

报告相同问题?

悬赏问题

  • ¥20 要这个数学建模编程的代码 并且能完整允许出来结果 完整的过程和数据的结果
  • ¥15 html5+css和javascript有人可以帮吗?图片要怎么插入代码里面啊
  • ¥30 Unity接入微信SDK 无法开启摄像头
  • ¥20 有偿 写代码 要用特定的软件anaconda 里的jvpyter 用python3写
  • ¥20 cad图纸,chx-3六轴码垛机器人
  • ¥15 移动摄像头专网需要解vlan
  • ¥20 access多表提取相同字段数据并合并
  • ¥20 基于MSP430f5529的MPU6050驱动,求出欧拉角
  • ¥20 Java-Oj-桌布的计算
  • ¥15 powerbuilder中的datawindow数据整合到新的DataWindow