-2

I want to fill up TableE, and I have these tables.

TableA

+------+--------+--------+
| A_ID | A_NAME | A_TYPE |
+------+--------+--------+
|   1  |  apple |    1   |
+------+--------+--------+

TableB

+------+---------+--------+
| B_ID | B_NAME  | FROM_A |
+------+---------+--------+
|   1  | A_NAME  | A_ID   |
+------+---------+--------+

TableC

+-------+------------+
|  C_ID |   C_NAME   |
+-------+------------+
| A_TYPE|    fruit   |
+-------+------------+
| A_TYPE| vegetables |
+-------+------------+

TableD

+------+---------+
| D_ID | D_NAME  |
+------+---------+
|   1  |  fruit  |
+------+---------+

TableE

+------+--------+
| E_ID | E_NAME |
+------+--------+
| B_ID |  D_ID  |
+------+--------+

How can I fill TableE with TableB B_ID and TableD D_ID, where the C_Name = with D_Name, and between TableC and TableD no key, only through TableA and TableB, where the A_ID is the key.

So, if apple is a fruit, write in TableE the B_ID and D_ID, with one SQL statement. How can I do this?

I have 2000 row in TableA and TableB I want to compare the C_Name with D_Name, and if its the same, write in the TableE the ID from TableB and the ID from TableD.

Miszter Soul
  • 118
  • 10

1 Answers1

0
  INSERT INTO TableE (E_ID , E_NAME)
  SELECT b.B_ID ,d.D_ID FROM TableA a 
  INNER JOIN TableB b ON b.FROM_A = a.A_ID
  INNER JOIN TableC c ON c.C_ID  = a.A_TYPE
  INNER JOIN TableD d ON  d.D_NAME = c.C_NAME
echo_Me
  • 37,078
  • 5
  • 58
  • 78
  • Error in the 6. line #1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'SET E_ID = b.B_ID , E_NAME = d.D_ID' at line 6 – Miszter Soul Aug 06 '13 at 11:38
  • @MiszterSoul check now myedited answer – echo_Me Aug 06 '13 at 11:40