MySQL Forums
Forum List  »  Newbie

Re: MySQL Join 4 Tables
Posted by: Phillip Ward
Date: February 01, 2023 07:23AM

[Still not what I asked for (create table, insert), but ...]
Something like this should get you close to what you want:

select 
  A.ID 
, A.Des
, C.P_DATE
, C.ITEM_NO  --- table c has no column called ITEM_NO !! 
, D.REF_NO
, D.D_DATE
from table_a A
left join table_b B 
     on A.ID = B.ID
left join table_c C 
     on B.P_ID = C.P_ID
left join table_d D 
     on A.ID = D.ID

+----+-----+------------++--------+------------+
| ID | Des | P_DATE     || REF_NO | D_DATE     |
+----+-----+------------++--------+------------+
|  1 | xxx | 2022/10/12 ||        |            |
|  2 | yyy |            || B13    | 2022/09/30 | 
|  3 | zzz | 2022/10/19 ||        |            |
|  4 | aaa |            || L84    | 2022/09/22 | 
+----+-----+------------++--------+------------+

Regards, Phill W.

Options: ReplyQuote


Subject
Written By
Posted
January 29, 2023 11:48PM
January 30, 2023 07:25AM
January 31, 2023 08:26AM
January 31, 2023 10:36AM
Re: MySQL Join 4 Tables
February 01, 2023 07:23AM
February 02, 2023 12:17AM
February 06, 2023 08:16AM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.