[英]Mysql Multiple joins from 4 tables
I need to list all the poetry from users that check in for the night. 我需要列出所有在夜间登记入住的用户的诗歌。 I have a custom table and use wordpress.
我有一个自定义表格,并使用wordpress。
I have a table called checkin with a field called ID which is the wordpress users id. 我有一个名为checkin的表,其中包含一个名为ID的字段,该字段为wordpress用户ID。 I also have a filed called date , which is a timestamp.
我也有一个称为date的归档文件,它是一个时间戳。
The poems get stored in the ' wp0k_posts ' table, The user again is stored as ID . 这些诗将存储在“ wp0k_posts ”表中,用户又将存储为ID 。 I need to grab of course the ' post_content ' and ' post_title ' where the ' post_type ' is equal to ' um_story '.
我当然需要抓住“ post_content ”和“ post_title ”,其中“ post_type ”等于“ um_story ”。
The real difficult part is that wordpress stores the users first name and last name in a separate table called wp0k_usermeta . 真正的困难之处在于,wordpress将用户的名字和姓氏存储在另一个名为wp0k_usermeta的表中。 user_id is equal to wp0k_users.ID .
user_id等于wp0k_users.ID 。 the store the values like so filed " first_name " = "Jim", " last_name " = "Harris"
像这样存储的值“ first_name ” =“ Jim”,“ last_name ” =“ Harris”
I'm hoping to return: wp0k_users.ID | 我希望返回:wp0k_users.ID | wp0k_usermeta.first_name |
wp0k_usermeta.first_name | wp0k_usermeta.last_name |
wp0k_usermeta.last_name | wp0k_posts.post_title |
wp0k_posts.post_title | wp0k_posts.
wp0k_posts。 post_content Where checkin.date == Today
post_content其中checkin.date ==今天
Looking at your question it looks like all of the table have connection to wp0k_user
table . 查看您的问题,似乎所有表都与
wp0k_user
表建立了连接。 Your table naming is so confusing but here is what I've tried so far. 您的表命名是如此混乱,但这是到目前为止我尝试过的。 If you could edit your question with more explanation then we could help further.
如果您可以使用更多解释来编辑您的问题,那么我们可以提供进一步的帮助。 :
:
select wu.id,wum.first_name, wum.last_name,wp.post_title,wp.post_content
from wp0k_users wu join wp0k_posts wp on wp.user_id = wu.id
join wp0k_usermetadata wum on wum.user_id=wu.id
join checkin c on c.user_id=wu.id
where c.date >= CURDATE();
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.