0

我目前拥有的 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 。

-Image_id | 对象_uid | Object_utitle

-img1 | 对象1 | 标题 1

-img2 | 对象2 | 标题 2

-img2 | 对象2 | 标题 3

有没有办法做到这一点?

4

4 回答 4

1

尝试这个:

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) )
于 2013-08-05T15:44:30.133 回答
0
Select object_uid, object_utitle from object_table where object_status = 2 and object_place like "%some_keyword%" LIMIT 0,1

它只会选择一个条目,ORDER BY DESC/ASC根据您想要显示的内容添加。

于 2013-08-05T15:33:16.660 回答
0

你可以加入表格。

   Select i.Image_id , i.file_path , o.object_uid  
   FROM images i
   INNER JOIN temp_images t ON t.image_id = i.image_id
   INNER JOIN object_table o ON o.object_uid = t.object_uid
   WHERE object_status = 2 and object_place like "%some_keyword%"
于 2013-08-05T15:49:08.103 回答
0

使用多个内部连接,你应该尝试这样的事情:

SELECT imgs.image_id, obj.object_uid, obj.object_utitle
    FROM images AS imgs
INNER JOIN temp_images AS tmp_imgs
    ON tmp_imgs.image_id = imgs.image_id
INNER JOIN object_table AS obj
    ON tmp_imgs.object_uid = obj.object_uid
WHERE obj.object_status = 2
    AND obj.object_place LIKE "%some_keyword%"
于 2013-08-05T15:54:16.957 回答