我目前的sql查询如下。我尝试了一些联合查询,但没有成功。
Select file_path
from images
where image_id In (
Select image_id
from temp_images
where object_uid IN (
Select object_uid
from object_table
where object_status = 2 and object_place like "%some_keyword%"))`
Select object_uid, object_utitle
from object_table
where object_status = 2 and object_place like "%some_keyword%"`
两个查询可能返回许多行。我想像这样返回 file_path 和 object_uid 。
-图像 ID |对象_uid |对象_标题
-img1 |对象1 |标题1
-img2 |对象2 |标题2
-img2 |对象2 |标题3
有什么办法可以做到这一点吗?
最佳答案
试试这个:
Select a.file_path, b.object_uid, b.object_utitle
from images a, (Select object_uid, object_utitle
from object_table
where object_status = 2 and object_place like "%some_keyword%") b
where image_id In (
Select image_id
from temp_images
where object_uid IN (b.object_uid) )
关于mysql - 如何从两个查询中只返回一个查询结果,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18061911/