Shafiq Ahmed
Shafiq Ahmed

Reputation: 57

Merge and replace table id with name of two table SQL

table customers:

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

table orders:

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

Is possible with one query have this result?

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

Upvotes: 2

Views: 1566

Answers (1)

echo_Me
echo_Me

Reputation: 37233

here how you can do it

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

DEMO HERE

OUTPUT:

   ID   CID     ORDERNAME   COLORS
   8    name2   name              5

Upvotes: 3

Related Questions