sql - Help with SQLITE query -



sql - Help with SQLITE query -

i have 3 tables task , tasktag , tag below..

create table task (task_id text primary key, subject text); create table tasktag (task_tag_id text primary key, task_id text, tag_id text); create table tag (tag_id text primary key, tag text);

i want find record in task there 2 matching tags: tag1, tag2

how sql look, have tried can't work using and, can using or..

select * task bring together tasktag on task.task_id = tasktag.task_id bring together tag on tasktag.tag_id = tag.tag_id tag = "tag1" , tag = "tag2"

use:

select * task bring together tasktag on task.task_id = tasktag.task_id bring together tag on tasktag.tag_id = tag.tag_id tag in ('tag1', 'tag2') grouping task.task_id having count(distinct tag) = 2

the having count(distinct ...) needs equal number of in parameters, or risk seeing false positives (ie duplicates of tag1 count 2, etc).

sql sqlite

Comments

Popular posts from this blog

iphone - Dismissing a UIAlertView -

c# - Can ProtoBuf-Net deserialize to a flat class? -

javascript - Change element in each JQuery tab to dynamically generated colors -