0

好的,我有两个选择语句

我想要做的是在一个选择语句中执行此操作,其中 im.alias_title =(in_image_alias_title OR a.user_id = user_id)AND a.approved = in_album_approved AND a.visible = in_album_visible;

我需要在两个结果集之间进行识别——有没有办法在查询中创建另一个列值,比如它是用户相册还是属于图像的相册。一张图片可以有多个相册。或者最好分开

/* Select all albums associated with an image */
SELECT a.alias_title, a.title, a.hits, a.created_on, a.updated_on, a.updated_by 
FROM album a 
INNER JOIN album_image ai ON a.id = ai.album_id 
INNER JOIN image im ON ai.image_id = im.id
WHERE im.alias_title =in_image_alias_title AND a.approved = in_album_approved AND a.visible = in_album_visible;

/* Select a users albums */
SELECT a.alias_title, a.title, a.hits, a.created_on, a.updated_on, a.updated_by 
FROM album a 
INNER JOIN album_image ai ON a.id = ai.album_id 
INNER JOIN image im ON ai.image_id = im.id
WHERE a.approved = in_album_approved AND a.visible = in_album_visible AND a.user_id = user_id;
4

1 回答 1

0

您可以在描述时指定过滤条件,并使用布尔表达式的结果来指示记录所在的原始查询/查询:

SELECT a.alias_title, a.title, a.hits, a.created_on, a.updated_on, a.updated_by,
       im.alias_title = in_image_alias_title AS q1,  -- was included in 1st query
       a.user_id      = user_id              AS q2   -- was included in 2nd query
FROM   album       a
  JOIN album_image ai ON a.id        = ai.album_id
  JOIN image       im ON ai.image_id = im.id
WHERE  (im.alias_title = in_image_alias_title OR a.user_id = user_id)
   AND a.approved = in_album_approved
   AND a.visible  = in_album_visible
于 2012-10-02T18:38:34.660 回答