MikeFairbrother (12th May 2010)
Just wondering if someone can help here.
I have a PHP script with an SQL query. The MySQL query picks up data from one table called
'info'. It has the following fields (as I am just testing at the moment)
[ID | UserID | Email | Phone]
I have another table in the mysql database called 'users'. This has
[ID | UserID | Surname | Forename]
The UserID is the same. When a 'user' submits their 'info', it submits their info into the info database.
I am wanting to display results from 'info' in order of 'surname' by using the "UserID".
So that would use the UserID to cross reference to find the users username and display the phone numbers and email addresses in order of surname.
(because part of the PHP script already has a function to display the username in the table of info by picking up the forename, surname based on the userID).
Does anyone know the correct MySQL statement I would use to achieve this?
I seem to remember doing it before but can't get it to work anymore the way I thought was possible.
Many thanks,
Mike
Last edited by MikeFairbrother; 12th May 2010 at 02:22 PM.

Code:SELECT u.UserID, u.Surname, u.Forename, i.Email, i.Phone FROM users AS u LEFT JOIN info AS i ON u.UserID=i.UserID ORDER BY surname, forename ASC;
MikeFairbrother (12th May 2010)
Many thanks :-)
There are currently 1 users browsing this thread. (0 members and 1 guests)