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!

Can order by the most attributes matched be done in a SQL statement?

Status
Not open for further replies.

Guest_imported

New member
Jan 1, 1970
0
Hi,

I'm using an Access database and would like to know whether the follow query is possible.

I've written the query in broken English in order to make my intention transparent.

SELECT * FROM Fruits WHERE Fruit="Apple" OR Color="Green" OR Shape="Round" OR Texture="Smooth" ORDER BY the rows that have the most of these attributes first.

Thanks

Marcus

 
is it good?
select t.x as x, y.*
(select a, count(a) as x from y group by a) as t inner join y on t.a = y.a
order by x John Fill
1c.bmp


ivfmd@mail.md
 
How about this...

SELECT
Cnt=CASE Fruit WHEN 'Apple' Then 1 Else 0 End +
CASE Color WHEN 'Green' Then 1 Else 0 End +
CASE Shape WHEN 'Round' Then 1 Else 0 End +
CASE Texture WHEN 'Smooth' Then 1 Else 0 End,
*

FROM Fruits
WHERE Fruit='Apple'
OR Color='Green'
OR Shape='Round'
OR Texture='Smooth'

ORDER BY 1 Desc Terry
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top