简体   繁体   English

MySQL选择所有记录

[英]MySQL Select all records

I have to tables: user and userimages . 我要表: useruserimages 在此处输入图片说明

Right now, I'm using the following query: 现在,我正在使用以下查询:

SELECT *  FROM   users u INNER JOIN userimages ui ON u.id=ui.userid;

Yes. 是。 It retrieved the records if the userid and id is equal. 如果userid和id相等,则检索记录。 What I really want to do is to select all records from table users even if its id is not present on the second table (userimages) 我真正想做的是从表用户中选择所有记录,即使其ID在第二个表中也不存在(userimages)

My question is how to select all records in the users table with or withou userid on the second table? 我的问题是如何在用户表中选择第二个表上带有或不带userid的所有记录?

您正在寻找一个LEFT JOIN,它将从第一个表中拉出所有行,并在适用的情况下联接。

SELECT *  FROM   users u LEFT JOIN userimages ui ON u.id=ui.userid;

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

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