0

I am having trouble with a MySQL join query - unfortunately I am not too good with joins.

Table page_section:
-------------------
id
page_id
name
display_order


Table page_section_sub:
-----------------------
id
page_section_id
page_id
content

One page_section can have many page_section_sub

On my page I want to display rows from page_section_sub ordered by page_section.display_order

Currently I have this:

$query="SELECT * FROM page_section_sub WHERE page_section_id IN (1,2,3,4,5) 
ORDER BY display_order";

But this is not working as it is missing the join. How do I do this?

Rahul
  • 76,197
  • 13
  • 71
  • 125
MAX POWER
  • 5,213
  • 15
  • 89
  • 141
  • something like that: `select pss.* from page_section_sub pss join page_section ps on pss.page_section_id = ps.id where ps.id between 1 and 5 order by ps.display_order` – greut Jan 05 '12 at 17:37

3 Answers3

2
select pss.*
from page_section_sub pss
inner join page_section ps on pss.page_section_id = ps.id
where pss.page_section_id in (1, 2, 3, 4, 5)
order by ps.display_order
D'Arcy Rittich
  • 167,292
  • 40
  • 290
  • 283
0

Try this way:

SELECT * FROM page_section
LEFT JOIN page_section_sub ON page_section.page_id = page_section_sub.page_id
WHERE page_section_id IN (1,2,3,4,5) 
ORDER BY display_order;
Rahul
  • 76,197
  • 13
  • 71
  • 125
Petar Sabev
  • 848
  • 6
  • 12
0

Try this:

Select page_section_id.* from page_section_id natural join page_section 
WHERE page_section_id IN (1,2,3,4,5) order by page_section_id.display_order 
Rahul
  • 76,197
  • 13
  • 71
  • 125