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 IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

order by relevance/relational tables query

Status
Not open for further replies.

blondrob

Programmer
Apr 29, 2002
4
GB
Hi,
I'm trying to sort results using sets of conditions returning either 1 or 0.

The following sql is looking at two relational tables where tbljobs.id is related to tbljob_location.job_id

Code:
SELECT distinct tbljobs.*, 
(tbljobs.phase='Pre School' and tbljobs.id=tbljob_location.job_id AND tbljob_location.location_id='14') as Relevance FROM tbljobs,tbljob_location WHERE tbljobs.active='y' AND (tbljobs.phase='Pre School' or (tbljobs.id=tbljob_location.job_id AND (tbljob_location.location_id='5' or tbljob_location.location_id='14')) ) ORDER BY Relevance DESC limit 0, 5
when the following is satisfied i get a duplication of the record-

Code:
tbljobs.id=tbljob_location.job_id AND tbljob_location.location_id='14'

each record seems identical except for Relevance which has value=1 in 1st instance and 0 in 2nd.

help would be appreciated
(the page itself is at )
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top