Silvor Posted May 12, 2010 Posted May 12, 2010 (edited) 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 Edited May 12, 2010 by Silvor
powdarrmonkey Posted May 12, 2010 Posted May 12, 2010 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; 1
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now