| Author |
Topic |
|
deco10
Starting Member
28 Posts |
Posted - 2010-07-07 : 09:35:21
|
What I need to do is take the label id(s) inputted by user and find all of the articles and have all the labels the user is searching for (this is simple with only one label inputted)Any help? table: labelsid, label_texttable: articlesid, title, bodytable: label_articlesid, label_id, article_id |
|
|
webfred
Master Smack Fu Yak Hacker
8781 Posts |
Posted - 2010-07-07 : 09:42:15
|
It is starting with user input.It is ending with a select that reads from label_articles joining articles and labels.But between starting and ending we need more information.Do you have stored procedure and the input is coming via parameter or what do you mean regarding "inputted by user"?Do you talk about multivalue parameter?What datatypes are involved? No, you're never too old to Yak'n'Roll if you're too young to die. |
 |
|
|
deco10
Starting Member
28 Posts |
Posted - 2010-07-07 : 09:51:48
|
| its for a web app. I don't have any stored procs.For now we can just say I'm looking for articles that have tag id 2 AND 3 |
 |
|
|
webfred
Master Smack Fu Yak Hacker
8781 Posts |
Posted - 2010-07-07 : 10:03:35
|
selecta.id,a.title,a.body,l.label_textfrom label_articles lajoin articles a on la.article_id = a.idjoin label l onl.id = la.label_idwhere la.article_id in (2,3) No, you're never too old to Yak'n'Roll if you're too young to die. |
 |
|
|
deco10
Starting Member
28 Posts |
Posted - 2010-07-07 : 10:12:07
|
| I expect this will return articles with tag id 2 OR tag id 3I'll give it a whirl though. |
 |
|
|
webfred
Master Smack Fu Yak Hacker
8781 Posts |
Posted - 2010-07-07 : 10:17:00
|
I don't see a "tag id" so I don't know what you mean... No, you're never too old to Yak'n'Roll if you're too young to die. |
 |
|
|
deco10
Starting Member
28 Posts |
Posted - 2010-07-07 : 10:37:44
|
quote: Originally posted by deco10For now we can just say I'm looking for articles that have tag id 2 AND 3
An article has many tags through article_tags.I need to find the articles that have tags with id 2 and 3I'm not sure if I clarified that or just made more of a mess of it :) |
 |
|
|
webfred
Master Smack Fu Yak Hacker
8781 Posts |
Posted - 2010-07-07 : 10:52:40
|
Can you please give example data and wanted output? No, you're never too old to Yak'n'Roll if you're too young to die. |
 |
|
|
deco10
Starting Member
28 Posts |
Posted - 2010-07-07 : 11:02:59
|
| ** sorry for the confusion: when I said "tag" I meant "label"select all articles that _have_ labels with id 1 AND 2so I want to select articles that have label "work" and label "photos"The table label_articles shows that the article "my article1" has labels "work" and "photos".So I would like to be able to find an article based on labels. If I was only looking for one tag I could do it like this:SELECT * FROM articles JOIN article_labels ON article_labels.article_id = article_idJOIN labels ON article_labels.label_id = label.idWHERE label.id = 1table: labelsid, label_text1 , work2 , photos3 , schooltable: articlesid, title, body1 , "my article1", "texttext"2 , "my article2", "texttext"3 , "my article3", "texttext"table: label_articlesid, label_id, article_id1 , 1 , 12 , 2 , 13 , 3 , 2 |
 |
|
|
webfred
Master Smack Fu Yak Hacker
8781 Posts |
Posted - 2010-07-07 : 11:12:29
|
This?selecta.id,a.title,a.body,l.label_textfrom label_articles lajoin articles a on la.article_id = a.idjoin label l onl.id = la.label_idwhere la.label_id=1and exists (select * from label_articles la2 where la2.article_id = la.article_id and la2.label_id=2) No, you're never too old to Yak'n'Roll if you're too young to die. |
 |
|
|
|