我对 SQL 很陌生,花了几个小时搜索,但所有文章都指向或多或少相同
SELECT column_name(s)
FROM table1
RIGHT JOIN table2
ON table1.column_name = table2.column_name;
贝娄是我的代码,但老实说我不确定我在这里做错了什么。
"SELECT * FROM user_private_store WHERE store_type=@STORE_TYPE " +
"RIGHT JOIN user_private_store_items " +
"ON user_private_store.id = user_private_store_items.id";
我想通过 ID 连接两个表,保留左侧的 id 并从右侧表 user_private_store_items 获取其他参数
我在关键字“right”附近发现语法错误
最佳答案
只需输入 where
连接后的子句:
"SELECT * FROM user_private_store s " +
"RIGHT JOIN user_private_store_items i " +
"ON s.id = i.id " +
"WHERE store_type=@STORE_TYPE"
注释:
表别名使查询更易于阅读和理解。我修改了您的查询以使用它们
您需要添加前缀
store_type
在where
子句与其所属的表一起使用,以避免歧义avoir
select *
;最好枚举您要选择的所有列
关于sql - 关键字 'right' 附近的语法不正确,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58737874/