Jump to content

Join multiple tables and group multiple columns to the same alias


Roland_D

Recommended Posts

I've been looking everywhere for the solution but I seem to be missing a little piece of something here..

 

I have 3 tables: pages, categories, menu

 

PAGES

 

ID | title

1 | Home

2 | About

 

CATEGORIES

ID | name

6 | Flowers

9 | Cats

 

MENU

 

ID | pID | cID

1 | 1 | 0

2 | 2 | 0

3 | 0 | 6

4 | 0 | 9

 

What I'm trying to do is this

 

SELECT p.title AS mytitle, c.name AS mytitle, m.ID

FROM menu m

LEFT JOIN pages p ON p.ID=m.pID

LEFT JOIN categories c ON c.ID=m.cID;

 

What I get however is

 

ID | mytitle | mytitle

1 | Home | NULL

2 | About | NULL

3 | NULL | Flowers

4 | NULL | Cats

 

 

What I need is instead

 

ID | mytitle

1 | Home

2 | About

3 | Flowers

4 | Cats

 

 

Thank you guys!

Edited by Roland_D
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.