...

View Full Version : Join three tables in a SQL statement.



NinjaTurtle
01-18-2005, 02:42 PM
Dear,

i have 3 tables : Level1, Level2 and Level3
Structure:
Level1
=====
L1Code L1Name

Level2
=====
L1Code L2Code L2Name

Level3
=====
L1Code L2Code L3Code L3Name


How to list the records like


L1
==
L2
---
- L3

L1
==
L2
---
- L3
- L3
L2
---
- No Record.


L1
==
L2
---
- No Record.
L2
---
- No Record.

But in the Level2, they might not have any record(Level3)

I can make it if i use 2 SQL and with 2 loops
But what i facing is how to make it in a SQL Statement???

A1ien51
01-18-2005, 06:00 PM
I think it is something like this (not positive):


SELECT Level1.L1Code,
Level1.L1Name,
Level2.L2Code,
Level2.L2Name,
Level3.L3Code,
Level3.L3Name
FROM Level1
LEFT OUTER JOIN Level2 ON Level1.L1Code = Level2.L2Code
LEFT OUTER JOIN Level3 ON Level2.L2Code = Level3.L3Code


Eric

NinjaTurtle
01-19-2005, 06:11 AM
Its work... TQ



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum