Giulio Mastrosanti <giu...@cantoberon.it> wrote:
> But the user can select to search for A records that MATCH ALL the B records 
> selected, in this case the A records that are linked
> to ALL of record B with id 1, 2, 3 
> 
> I have arranged the query this way:
> 
> select a_id from a_b where b_id in (1,2,3) group by a_id having count(b_id) = 
> 3
> 
> this query returns only A with id 1, because checking if the count of the 
> rows grouped is equal to the number of the B ids
> specifyed in the query, I have returned only the A records that are linked to 
> ALL the B records selected for the query. 
> 
> Now my problem is, that for a number of reasons now I can have an A record 
> linked to more than one records B with the same ID, so
> I could have a table A_B filled this way: 
> 
> A_id | B_id
> 1      1
> 1      2
> 1      3
> 2      1
> 2      2
> 2      2

select a_id from (select distinct a_id, b_id from a_b)
where b_id in (1,2,3) group by a_id having count(b_id) = 3;

Igor Tandetnik

_______________________________________________
sqlite-users mailing list
sqlite-users@sqlite.org
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users

Reply via email to