答案 0 :(得分:1)
您需要使用LEFT JOIN
。以下查询会根据user
将您的bicycle
表格与userID
表格相关联,并返回所有自行车和用户字段
SELECT b.*, u.*
FROM registered_users u
LEFT JOIN registered_bicycle b ON (u.userID = b.userID)
如果您想要特定的自行车字段,请在其前面添加b.
示例:
SELECT b.brand, b.model, b.color...
答案 1 :(得分:0)
单击SQL选项卡并键入:
SELECT * FROM `registered_bicycle` JOIN `registered_users` ON `registered_users`.`userID` = `registered_bicycle`.`userID`
并运行它
答案 2 :(得分:0)
你必须像这样从user_table到bicycle_table创建一个外键。
user_table has user_id = user_1,name=John Richard
bicycle_table has user_id = user_1,description = Bicycle1
to fetch the data:
select a.user_id, a.name,b.description from (select user_id, name from user_table) as a left join (select user_id,description from bicycle_table) as b on a.user_id = b.user_id