Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

ORDER by query problem 1

Status
Not open for further replies.

dle46163

IS-IT--Management
Jul 9, 2004
81
US
Hi!

In a PHP script I have this query:

$query = "SELECT name, description FROM mytable
WHERE file_id='$file_id'
AND sector='1'
OR file_id='$file_id'
AND sector='2'
ORDER by name";

I can't get the sort to work and am pretty sure I've got the syntax wrong for the "ORDER by" part.. any thoughts would be great!

 
your order by is fine, it is your mix of ORs and ANDs that is the problem.

What you most likely are after is this:

Code:
 $query = "SELECT name, description FROM mytable
  WHERE 
(file_id='$file_id'
  AND sector='1')
  OR 
(file_id='$file_id'
  AND sector='2')
  ORDER by name";
 
actually, guelphdad, your parentheses don't change a thing :)

dle46163, the ORDER BY looks okay to me

what order did you want the results in?


p.s. you can also write the WHERE clause as ...

WHERE file_id = '$file_id' AND sector IN ( 1,2 )




r937.com | rudy.ca
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top