简体   繁体   English

从mysql中选择记录在哪里

[英]Selecting records from mysql where

I am having trouble sorting out a query (making me nuts) if you look at the SQL below, notice the and/or. 如果你查看下面的SQL,我在整理查询(让我疯了)时遇到问题,请注意和/或。 I need to essentially combine the images for the artist in 2 categories into one call BUT if I use the below sql I get all of the images in the first category as well as all the images from every artist in the second category rather than the ones for the particular artist. 我需要将两个类别中艺术家的图像组合成一个调用但是如果我使用下面的sql我得到第一个类别中的所有图像以及第二个类别中每个艺术家的所有图像而不是第二个类别中的所有图像对于特定的艺术家。 If you use an AND call it only gets images in both. 如果您使用AND调用它只会在两者中获取图像。 So basically hopefully this made sense. 所以基本上希望这是有道理的。 All help is appreciated. 所有帮助表示赞赏。

SELECT i.img_name, i.ordered_by, i.img_description, a.artist_path_name, a.artist_id, a.artist_dir, a.artist_name, a.first_name, a.last_name, a.artist_titletag, a.artist_metadesc, a.artist_metakey, ck.catKey_id, ck.keyword
        FROM images AS i JOIN artists AS a USING (artist_id)
        JOIN img_cat_table AS imc USING (img_id)
        JOIN catKeys AS ck USING (catKey_id)
        WHERE artist_name = 'j' AND catKey_id = 5 OR catKey_id = 1

if you are using both AND/OR then you will want to use parentheses to determine the order 如果您同时使用AND/OR则需要使用括号来确定顺序

WHERE (artist_name = 'j') AND (catKey_id = 5 OR catKey_id = 1)

Or even use the following WHERE clause: 甚至使用以下WHERE子句:

WHERE (artist_name = 'j') AND (catKey_id IN (5, 1))

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM