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.
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;