SQL INNER JOIN还是最佳选择?

时间:2014-06-22 00:13:37

标签: php mysql sql

我想请一位对INNER JOIN有良好经验的人提供帮助。这里我有两张桌子

Table 1
===========
id | name 
===========
1  | john
2  | mark

Table 2
======================================
id | customer_id | like_to_eat
======================================
1  | 1           | cake
2  | 2           | cake
3  | 1           | pudding
4  | 1           | chocolate

我想查询找出哪些顾客想吃“蛋糕”

我已经完成了这个

SELECT * 
FROM table1 
INNER JOIN table2 
ON table1.id = table2.customer_id 
WHERE table2.like_to_eat ='cake'

但是我再次得到正确的$row['id']

任何帮助表示感谢。

1 个答案:

答案 0 :(得分:1)

基于评论

SELECT table1.id as TheIDIReallyNeed
, table1.name
, table2.id
, table2.customer_id
, table2.like_to_eat
FROM table1 
INNER JOIN table2 
ON table1.id = table2.customer_id 
WHERE table2.like_to_eat ='cake'
相关问题