MySQL Forums
Forum List  »  MySQL Query Browser

MySQL Query: JOIN rows of 1 table
Posted by: steve de ridder
Date: May 21, 2010 01:19PM

Hi there,

I have a table of my DB that has 3 fiels:
studentid / branch / result

So every student has 2 entries: one for his academical results and one for his sports results

1 / ACADEMIC / 13
1 / PHYSICAL / 12
2 / ACADEMIC / 17
2 / PHYSICAL / 12
3 / ACADEMIC / 10
3 / PHYSICAL / 11

I would like to create an SQL query to get all students, ordered by their academical result.

So I should get

studentid / academic / physical
2 / 17 / 12
1 / 13 / 12
3 / 10 / 11

The idea

SELECT DISTINCT studentid FROM table WHERE `branch`='ACADEMIC'
JOIN table ON studentid WHERE `branch`='PHYSICAL'
ORDER BY (result IN table WHERE branch = 'ACADEMIC')

is offcourse not working, but I don't see a way to do so. Joining these lines will make it impossible to distinguish the results from the two branches.

Could anyone please give me a help in how to do so?
Thanks a lot!

Sincerely,
Steve (Belgium)

Options: ReplyQuote


Subject
Written By
Posted
MySQL Query: JOIN rows of 1 table
May 21, 2010 01:19PM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.