如果列值不存在,则不要加入表

编程入门 行业动态 更新时间:2024-10-27 11:15:31
本文介绍了如果列值不存在,则不要加入表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 SELECT `wp_emu_theme_contact_page`.`firstName` , `wp_emu_theme_contact_page`.`city` , `wp_emu_theme_contact_page`.`state` , `wp_posts`.`post_content` , `wp_posts`.`post_date` , `wp_posts`.`post_type` , `wp_posts`.`ID` , `wp_emu_theme_testimonials`.`permission` , `wp_emu_theme_testimonials`.`userID` , `wp_users`.`user_login` , `wp_usermeta`.`meta_value` FROM `wp_emu_theme_testimonials` INNER JOIN `wp_emu_theme_contact_page` ON (`wp_emu_theme_testimonials`.`contactID` = `wp_emu_theme_contact_page`.`dbID`) INNER JOIN `wp_posts` ON (`wp_emu_theme_testimonials`.`postID` = `wp_posts`.`ID`) LEFT JOIN `wp_users` ON (`wp_emu_theme_testimonials`.`userID` = `wp_users`.`ID`) INNER JOIN `wp_usermeta` ON (`wp_usermeta`.`user_id` = `wp_users`.`ID`) WHERE (`wp_posts`.`post_type` ='testimonial' AND `wp_usermeta`.`meta_key` ='facebook_uid') OR (`wp_usermeta`.`meta_key` = 'null');

问题是表 wp_usermeta 可能没有 meta_key = 'facebook_uid'.在这种情况下,我没有收到这些条目.我想获得所有其他东西,即使那个 user_id 不存在 meta_key.如果是这样,那就太好了.如果我取出有关该表的部分,此查询将按预期工作.我试过没有手术室.我用的是mysql.

The problem is that table wp_usermeta might not have a meta_key = 'facebook_uid'. In that case, I am not getting those entries. I want to get all the other stuff, even if that meta_key doesnt exist for that user_id. And if it does, great. This query works as expected if I take out the parts regarding that table. I've tried without the OR. I am using mysql.

推荐答案

听起来您想使用 LEFT JOIN 并使 ON 的条件部分成为:

It sounds like you want to use LEFT JOIN and make that conditional part of the ON:

LEFT JOIN `wp_usermeta` ON (`wp_usermeta`.`user_id` = `wp_users`.`ID` AND `wp_usermeta`.`meta_key` ='facebook_uid')

更多推荐

如果列值不存在,则不要加入表

本文发布于:2023-10-28 18:48:59,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1537470.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:不存在

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!