[英]Mysql database join query from tables based on user login
I have 2 mysql tables - websites
and files
.我有 2 个 mysql 表 - websites
和files
。 I am expecting the end result table to show me all the website id's for each user logged in and to show the correct filename against them.我期待最终结果表向我显示每个登录用户的所有网站 ID,并针对他们显示正确的文件名。
I tried the following:我尝试了以下方法:
SELECT w1.websites_id ,w1.name ,f1.file_name ,f1.user_id
FROM websites w1
LEFT JOIN files f1 ON f1.websites_id=w1.websites_id
My current output is as below我目前的 output 如下
websites_id | websites_name |uploaded_user| file_name
----------------------------------------------------
1 | abc.com | user1 | test.png
2 | 123.com | user1 | start.png
2 | 123.com | user2 | fast.png4
----------------------------------------------------
Website1 (abc.com) for user 2 need to show up in my end table but not able to get that用户 2 的网站 1 (abc.com) 需要显示在我的茶几中,但无法获得
-----------------------------
Websites_id | websites_name |
1 | abc.com |
2 | 123.com |
----------------------------
Files Table
-----------------------------
Files_name | websites_id | uploaded_user|
------------------------------------------
test.png | 1 | user1
start.png | 2 | user1
fast.png | 2 | user2
------------------------------------------
I need expected output as我需要预期的 output 作为
websites_id | websites_name |uploaded_user| file_name
----------------------------------------------------
1 | abc.com | user1 | test.png
2 | 123.com | user1 | start.png
1 | abc.com | user2 | null
2 | 123.com | user2 | fast.png
1 | abc.com | user3 | null
2 | 123.com | user3 | null
Can you try running like this by using INNER JOIN Query您可以尝试使用 INNER JOIN Query 像这样运行吗
select w1.websites_id,w1.name,f1.file_name,f1.user_id from websites w1 INNER JOIN files f1 ON f1.websites_id=w1.websites_id select w1.websites_id,w1.name,f1.file_name,f1.user_id 来自网站 w1 INNER JOIN 文件 f1 ON f1.websites_id=w1.websites_id
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.