"Fuzzy" query results?

Last Post 02 Jan 2014 04:42 PM by russellb. 1 Replies.
AddThis - Bookmarking and Sharing Button Printer Friendly
  •  
  •  
  •  
  •  
  •  
Sort:
PrevPrev NextNext
You are not authorized to post a reply.
Author Messages Not Resolved
dstoltz
New Member
New Member

--
22 Dec 2013 07:33 AM
Hi all, I have the following query:

SELECT distinct a.aid
FROM apartments a, details d
WHERE a.aid = d.did
AND d.did in (13,25,27)


It basically joins two tables, apartments, and apartment details.

The above example is looking for an apartment that has 3 specific "details" (ie. like basement(13), gas service (25), and oil heat(27))

Is it possible to somehow return results if there are ANY matches?

Like only if 25 and 27 match...? (I think the IN would have to be replaced with -something-)

Hopefully it would return in order of number of matches, that is, I would want to see APARMENT #1 if it matched 2 or 3 things, and APARTMENT #2 second in the results if it matched only 1...

In other words, return results in the order of the number of matches...

Not sure if I'm explaining this correctly -
russellb
New Member
New Member

--
02 Jan 2014 04:42 PM
Sounds like you're looking for an OUTER JOIN. Something like this:

SELECT a.aid
FROM apartments a
LEFT JOIN details d
On a.aid = d.did
AND d.did in (13,25,27)
You are not authorized to post a reply.

Acceptable Use Policy