Re: [SQL] Matching several rows

2006-01-18 Thread Vraj Mohan
It is easier to think of this as SET INTERSECTION which leads to: SELECT id FROM urights WHERE right = 2 INTERSECT SELECT id FROM urights WHERE right = 5 INTERSECT SELECT id FROM urights WHERE right = 10 Ivan Steganov wrote: Thank you to everyone for the great help! I will evaluate all methods

Re: [SQL] Matching several rows

2006-01-18 Thread Patrick JACQUOT
Michael Glaesemann wrote: On Jan 18, 2006, at 21:48 , Volkan YAZICI wrote: AFAICS, the bottleneck in above query is ANY(ARRAY[]) clause usage. Instead of that, if you replace «rights = ANY(ARRAY[2,5,10])» with «rights IN (2,5,10)» it's overhead decreases to 0.200-0.300ms domain. explain an

Re: [SQL] Matching several rows

2006-01-18 Thread Ivan Steganov
Thank you to everyone for the great help!I will evaluate all methods in our query (It is actually well complexer then this sample) and choose the best one.Is there any "scientific" name to this kind of "several rows match for one result" data selection? Ivan

Re: [SQL] Matching several rows

2006-01-18 Thread Michael Glaesemann
On Jan 18, 2006, at 21:48 , Volkan YAZICI wrote: AFAICS, the bottleneck in above query is ANY(ARRAY[]) clause usage. Instead of that, if you replace «rights = ANY(ARRAY[2,5,10])» with «rights IN (2,5,10)» it's overhead decreases to 0.200-0.300ms domain. explain analyze SELECT id FROM ( SE

Re: [SQL] Matching several rows

2006-01-18 Thread Volkan YAZICI
On Jan 18 09:33, Michael Glaesemann wrote: > On Jan 18, 2006, at 20:55 , Volkan YAZICI wrote: > >SELECT t.id > >FROM (SELECT id, sum(1) AS s > > FROM id_n_rights > > WHERE rights = ANY(ARRAY[2,5,10]) > > GROUP BY id) AS t > >WHERE t.s = 3; AFAICS, the bottleneck in above query is

Re: [SQL] Matching several rows

2006-01-18 Thread Michael Glaesemann
On Jan 18, 2006, at 20:55 , Volkan YAZICI wrote: On Jan 18 05:43, Ivan Steganov wrote: IDRIGHT - 201 202 205 2010 302 3010 Now I need to find out which IDs have, say rights 2 AND 5 AND 10. SELECT t.id FROM (SELECT i

Re: [SQL] Matching several rows

2006-01-18 Thread Volkan YAZICI
Hi, On Jan 18 05:43, Ivan Steganov wrote: > IDRIGHT > - > 201 > 202 > 205 > 2010 > 302 > 3010 > > Now I need to find out which IDs have, say rights 2 AND 5 AND 10. SELECT t.id FROM (SELECT id, sum(1) AS s FROM

Re: [SQL] Matching several rows

2006-01-17 Thread Michael Glaesemann
On Jan 18, 2006, at 13:43 , Ivan Steganov wrote: A table URIGHTS which stores an ID and the RIGHTs this ID has. One ID may have many rights and accordingly records in table, sample: Now I need to find out which IDs have, say rights 2 AND 5 AND 10. select "ID" from "URIGHTS" as right_2 joi

[SQL] Matching several rows

2006-01-17 Thread Ivan Steganov
Hi,This is possibly absolutely trivial but I am lost...A table URIGHTS which stores an ID and the RIGHTs this ID has. One ID may have many rights and accordingly records in table, sample:ID        RIGHT -20        120        220        520        1030        230        10Now I n