我有两个名为customers和orders的MySQL数据库表,下面有一个示例......
customers
client_id | cust_name | cust_phone
--------------------------------
8273 | Mr Jones | 382749584
38 | Mr Smith | 773625372
9 | Mrs Brown | 922382938
orders
order_id | cust_id | product_id
--------------------------------
392 | 9 | 9388
23 | 2837 | 9283
488 | 17 | 28392
我正试图像这样做一个INNER JOIN ......
SELECT * FROM customers
JOIN orders
ON customers.cust_id=orders.client_id
WHERE ('client_id' LIKE '9')
它没有返回任何结果,但我希望它能显示client_id为9的字段
我哪里错了?
答案 0 :(得分:3)
您的查询错误。
SELECT * FROM customers
JOIN orders
ON customers.client_id =orders.cust_id
WHERE ('client_id' LIKE '9')
列client_id
并不存在于orders
表中。使用client_id = 9
代替like
查询。
答案 1 :(得分:1)
我认为你在这里犯了错误' client_id'
SELECT * FROM customers
JOIN orders
ON customers.cust_id=orders.client_id
WHERE client_id LIKE '9'
如果你写'''它取为字符串
答案 2 :(得分:0)
尝试这个完全匹配
SELECT * FROM customers JOIN orders ON customers.cust_id=orders.client_id WHERE orders.client_id = 9
或类似
SELECT * FROM customers JOIN orders ON customers.cust_id=orders.client_id WHERE orders.client_id Like '9'
这里可以使用外卡字符,例如
'%9%'
'9%'