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?

1
  • 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 Commented Jan 5, 2012 at 17:37

3 Answers 3

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
Sign up to request clarification or add additional context in comments.

Comments

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;

Comments

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 

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.