Quantcast
Channel: User Schwern - Stack Overflow
Viewing all articles
Browse latest Browse all 581

Answer by Schwern for SQL: Combining 'or','and', and 'order by'

$
0
0

where and order by and limit are separate clauses in the statement. Good indentation helps.

You want to make it clear that it is where (x and y) or z not where x and (y or z).

Select * From interview Inner join person On interview.person_id = person.id Where   (name like 'Annabel%' and person.address_street_name = 'Franklin Ave') or  (person.address_street_name = 'Northwestern Dr')Order By address_number Desc Limit 1

(Technically you don't need all those parens, but it's good to be clear.)

The where clause says it will match all Annabels who live on Franklin Ave OR it will match anyone that lives on Northwestern Drive. Those matches are ordered by their address_number in descending order. It will only return the first match.


Viewing all articles
Browse latest Browse all 581

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>