Help with optimising SQL query

Posted by user566013 on Stack Overflow See other posts from Stack Overflow or by user566013
Published on 2011-01-06T20:47:21Z Indexed on 2011/01/06 20:53 UTC
Read the original article Hit count: 193

Filed under:
|
|

Hi i need some help with this problem. I am working web application and for database i am using sqlite. Can someone help me with one query from databse which must be optimized == fast =)

I have table x:

ID | ID_DISH | ID_INGREDIENT
 1 | 1       | 2
 2 | 1       | 3
 3 | 1       | 8
 4 | 1       | 12

 5 | 2       | 13
 6 | 2       | 5
 7 | 2       | 3

 8 | 3       | 5
 9 | 3       | 8
 10| 3       | 2

.... ID_DISH is id of different dishes, ID_INGREDIENT is ingredient which dish is made of: so in my case dish with id 1 is made with ingredients with ids 2,3

In this table a have more then 15000 rows and my question is:

i need query which will fetch rows where i can find ids of dishes ordered by count of ingreedients ASC which i haven added to my algoritem.

examle: foo(2,4) will rows in this order:

ID_DISH | count(stillMissing)
    10  |   2
    1   |   3    

Dish with id 10 has ingredients with id 2 and 4 and hasn't got 2 more, then is

© Stack Overflow or respective owner

Related posts about sql

Related posts about sqlite