Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Query question.

New Here ,
Sep 04, 2009 Sep 04, 2009

Hi all,

I have a starter question about an SQL query. I have 3 simple tables:

table1table2table3
id1 (primary key)

id2 (PK)

id1 (FK from table1)

id3 (PK)

id2 (FK from table2)

Let's say the following content is in those tables:

table1table2table3
t1_1t2_1 (id1 = t1_1)t3_1 (id2 = t2_2)
t1_2t2_2 (id1 = t1_1)t3_2 (id2 = t2_2)
t1_3t2_3 (id1 = t1_3)t3_3 (id2 = t2_4)
t1_4t2_4 (id1 = t1_5)t3_4 (id2 = t2_4)
t1_5t2_5 (id1 = t1_5)t3_5 (id2 = t2_5)

Now I want to have to folowing output:

t1_1

- t2_1

- t2_2

-- t3_1

-- t3_2

t1_2

t1_3

- t2_3

t1_4

t1_5

- t2_4

-- t3_4

- t2_5

-- t3_5

Can this be done with on query?

Thanks for all your help.

Regards,

Samall

TOPICS
Getting started
556
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Sep 04, 2009 Sep 04, 2009
LATEST

First, I have heard good things about the book, "Teach Yourself SQL in 10 Minutes" by Ben Forta.

Next the query you want is

select your fields

from table1 t1 join table2 t2 on t1.id1 = t2.id1

join table3 t3 on t2.id2 = t3.id2

where whatever

order by t1.something, t2.something.

Then you can use the group attribute of cfoutput to arrange the results.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Resources