I am using INNER JOIN
to list the demos
and its descripcion
, but now I need to add to this info the tags
which are saved in a table tags
with a name
and a demo_id
that would be the way to associate each tag with its demo since this would be the same as id
of the table demos
.
Try to make this query and technically it works, but what it does is for example if there are 2 tags for that demo repeat the demo 2 times with each tag.
SELECT 'i'.'name',
'i'.'id',
'i'.'img',
'i'.'cat_id',
'd'.'description',
'd'.'url',
t.name as tags
FROM 'demos' i
INNER JOIN 'details' d ON 'i'.'id' = 'd'.'demo_id'
INNER JOIN tags t ON t.demo_id = i.id
ORDER BY 'i'.'id' ASC
The result that returns this is:
[
{
"name": "asdasda",
"id": "a12qdv",
"img": "https://xxx.s3.amazonaws.com/demos/1490127164214",
"cat_id": 0,
"description": "asdas",
"url": "http://asd/cms/demos",
"tags": "ReactJS"
},
{
"name": "asdasda",
"id": "a12qdv",
"img": "https://xxx.s3.amazonaws.com/demos/1490127164214",
"cat_id": 0,
"description": "asdas",
"url": "http://asd/cms/demos",
"tags": "PHP"
}
]
What I need to return, suppose there are 3 demos:
[
{
"name": "asdasda",
"id": "a12qrgw21dv",
"img": "https://xxx.s3.amazonaws.com/demos/1490127164214",
"cat_id": 0,
"description": "asdas",
"url": "http://asd/cms/demos",
"tags": "ReactJS, JavaScript"
},
{
"name": "asdasda",
"id": "a12qdv",
"img": "https://xxx.s3.amazonaws.com/demos/1490127164214",
"cat_id": 0,
"description": "asdas",
"url": "http://asd/cms/demos",
"tags": "PHP, ReactJS"
},
{
"name": "asdasda",
"id": "1231f2q21dv",
"img": "https://xxx.s3.amazonaws.com/demos/1490127164214",
"cat_id": 0,
"description": "asdas",
"url": "http://asd/cms/demos",
"tags": "PHP, NodeJS, Phyton"
}
]