Reputation: 33
I'm trying to get more values in a column and I'm testing it in phpMyAdmin:
I have a table Nieuws
that contains in this case ID
and a Title
.
I have a table called Nieuws_tags
where I give multiple tags to a item in column Nieuws
.
table Nieuws_tags
The final column is called Tags
that contains ID
and Beschrijving
Table Tags
Here is what I currently have:
SELECT * FROM (`Nieuws`) JOIN `Tags` ON `Tags`.`ID` = `Nieuws`.`ID`
WHERE `Tags`.`ID` = 1
1 | Titel 1 | 1 | QBNL
Right now I only get one value back QBNL
, but I gave it two values QBNL and QBBC. I'm pretty sure that my code is wrong but hopefully someone can help me.
EDIT: What I want to achieve:
Upvotes: 2
Views: 104
Reputation: 1197
Below would be the query if you need all the entries from tags.
SELECT *
FROM Nieuws t1
INNER JOIN Nieuws_tags t2 ON t2.ID-Nieuws = t1.ID
INNER JOIN Tags t3 ON t3.ID = t2.ID-tags
WHERE t3.ID-Nieuws = 1
Upvotes: 0
Reputation: 222592
You need to bring in junction table Nieuws_tags
:
SELECT *
FROM `Nieuws`
INNER JOIN `Nieuws_tags` ON `Nieuws_tags`.`ID-Nieuws` = `Nieuws`.`ID`
INNER JOIN `Tags` ON `Tags`.`ID` = `Nieuws_tags`.`ID-tags`
WHERE `Tags`.`ID` = 1
Upvotes: 2