954,164 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

ORDER BY

Hello all,

I have the following SQL statement.

SELECT a.airport_code AS AIRPORTCODE, a.airport_name AS AIRPORT, u.usr_id AS USERID, u.usr_fname AS FIRSTNAME, u.usr_lname AS LASTNAME, u.usr_email AS EMAIL,u.usr_airline AS AIRLINE, u.usr_airline_iatacode AS IATA, t.title AS TITLE
FROM users u LEFT JOIN userairportservices uas ON uas.usr_id_users = u.usr_id LEFT JOIN airport a ON a.airport_id = uas.airport_id_airport LEFT JOIN title t ON t.title_id = u.usr_title
WHERE a.airport_code= apcode


I want to sort by a.airport_name but every time I add ORDER BY a.airport_name ASC to the end of this query, it fails to load the page. Is there an issue with adding and ORDER BY to the end of this statement or should it go somewhere else in it?

Thanks

Dave

filch
Junior Poster
132 posts since Nov 2008
Reputation Points: 10
Solved Threads: 1
 

Hi

What is the WHERE a.airport_code= apcode? if any alias for apcode

guru12
Light Poster
44 posts since Jun 2009
Reputation Points: 8
Solved Threads: 6
 

try

SELECT a.airport_code AS airportcode, a.airport_name as airport, u.usr_id as userid, u.usr_fname as firstname, u.usr_lname as lastname, u.usr_email as email,u.usr_airline as airline, u.usr_airline_iatacode as iata, t.title as title from users u left join userairportservices uas on uas.usr_id_users = u.usr_id left join airport a on a.airport_id = uas.airport_id_airport left join title t on t.title_id = u.usr_title where airportcode = '%s' order by airport asc, $apcode
almostbob
Posting Sensei
3,147 posts since Jan 2009
Reputation Points: 571
Solved Threads: 376
 

try

SELECT a.airport_code AS airportcode, a.airport_name as airport, u.usr_id as userid, u.usr_fname as firstname, u.usr_lname as lastname, u.usr_email as email,u.usr_airline as airline, u.usr_airline_iatacode as iata, t.title as title from users u left join userairportservices uas on uas.usr_id_users = u.usr_id left join airport a on a.airport_id = uas.airport_id_airport left join title t on t.title_id = u.usr_title where airportcode = '%s' order by airport asc, $apcode

This has it. It is weird because this is more-or-less what I had and the page just came up blank. turns out that it has nothing to do with the query but something else on the page is cause the page not to render. ""sigh""

Thanks for your help

filch
Junior Poster
132 posts since Nov 2008
Reputation Points: 10
Solved Threads: 1
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You