Hey guys,
A little help: I'm having an issue with trying to retrieve a result from a query. Perhaps the table relationship is designed wrong. Maybe I'm using the wrong SQL commands. I'm very new to databases and SQL so I hope you can forgive me for this.
An article can have many keywords.
A keyword can belong to many articles.
A user can search for an article with more than 1 keyword, for example:
I want to search for an article that has keyword 1 (science) and keyword 5 (medical).
I tried to use this SQL statement:
SELECT Article ID
FROM Article_Keyword Table
WHERE Keyword_ID = '1' and '5'
But I know this does not work. I've been trying to figure out how to get multiple keywords in a single query.
Another thought was to use a subquery using something like this:
SELECT Article ID
FROM Article_Keyword Table
WHERE Keyword_ID = '1' IN
(SELECT Article ID
FROM Article_Keyword Table
WHERE Keyword_ID = '5')
But of course, that isn't the correct SQL statement.
Any help?
Thanks.
A little help: I'm having an issue with trying to retrieve a result from a query. Perhaps the table relationship is designed wrong. Maybe I'm using the wrong SQL commands. I'm very new to databases and SQL so I hope you can forgive me for this.
Code:
[B]Article Table[/B] - [I]Attrib: Article ID, Article Title[/I]
|
<> [B]Article_Keyword Table[/B] - [I]Attrib: Article ID, Keyword ID [/I]
|
[B]Keyword Table[/B] - [I]Attrib: Keyword ID, Keyword Description[/I]
An article can have many keywords.
A keyword can belong to many articles.
A user can search for an article with more than 1 keyword, for example:
I want to search for an article that has keyword 1 (science) and keyword 5 (medical).
I tried to use this SQL statement:
SELECT Article ID
FROM Article_Keyword Table
WHERE Keyword_ID = '1' and '5'
But I know this does not work. I've been trying to figure out how to get multiple keywords in a single query.
Another thought was to use a subquery using something like this:
SELECT Article ID
FROM Article_Keyword Table
WHERE Keyword_ID = '1' IN
(SELECT Article ID
FROM Article_Keyword Table
WHERE Keyword_ID = '5')
But of course, that isn't the correct SQL statement.
Any help?
Thanks.