Mysql:从表中提取
我在组合查询时遇到一些问题。我需要显示按顺序拉出的图像,如果它们位于“编辑”部分,那么如果它们有要在其中显示的顺序,将首先显示编辑图像,但如果它没有在该部分中排序,它将默认并拉出已订购的常规图像(可能不是编辑类型图像,但如果没有其他可用的图像,则为首选图像)。我现在所拥有的是下面的查询,但它不会首先拉出编辑排名的图像,而是“ordered_by”似乎优先。
SELECT i.img_name, a.artist_path_name, a.artist_dir, a.artist_name, ck.catKey_id
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 site = 'editorial' AND editorial_order = 1 OR ordered_by = 1 GROUP BY artist_name ORDER BY ed_banner
这可能是我错过的一些愚蠢的东西——任何和所有的帮助都是值得赞赏的。
I am having some trouble putting a query together. I need to show images pulled in the order of if they are in the "editorial" section then if they have an order to be displayed in it will show the editorial image first but if its not ordered in that section it would just default and pull the regular image that is ordered already (which may not be a editorial type image but is a preferred one if nothing else is available). What I have now is the query below BUT that doesn't pull the editorial ranked images first but rather the "ordered_by' seems to take precedence.
SELECT i.img_name, a.artist_path_name, a.artist_dir, a.artist_name, ck.catKey_id
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 site = 'editorial' AND editorial_order = 1 OR ordered_by = 1 GROUP BY artist_name ORDER BY ed_banner
Its probably something silly that I am missing -- any and all help is appreciated.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
尝试类似的方法:
Try something like:
或者以更简单的方式实现相同的想法
它只是利用 FALSE、TRUE 的顺序。
您应该从 WHERE 子句中删除相应的条件。
or the same idea in a simpler way
It simply utilizes the order of FALSE, TRUE.
You should remove the respective conditions from the WHERE clause.