2

表客户:

+----+------------+
| id | text       |
+----+------------+
| 33 | name1      | 
| 34 | name2      | 
| 35 | name3      | 
| 36 | name4      | 
+----+------------+

餐桌订单:

+----+--------+------------+----------+
| id |  cid   |  ordername |  colors  |
+----+--------+------------+----------+
|  8 |   34   |    name    |    5     |        
+----+--------+------------+----------+

一个查询可能有这个结果吗?

+----+--------+------------+----------+
| id |  cid   |  ordername |  colors  |
+----+--------+------------+----------+
|  8 | name1  |    name    |    5     |        
+----+--------+------------+----------+
4

1 回答 1

3

在这里你怎么做

   select o.`id`, `text` as cid , `ordername`, `colors` from orders o
   inner join customers c
   on  c.id = o.cid 

在这里演示

输出:

   ID   CID     ORDERNAME   COLORS
   8    name2   name              5
于 2013-05-23T22:58:07.647 回答