Modify MYSQL query to show message in case of not finding data

0

How can I modify this query so that if it does not find results from a demo_id in the tags table instead of showing the demo in the answer where the tags should go, say something like no category .

Inquiry

SELECT 'i'.'name', 'i'.'id', 'i'.'img', 'd'.'url', GROUP_CONCAT(t.name SEPARATOR ', ') 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  GROUP BY 'i'.'id' ORDER BY 'i'.'created_at' ASC

Answer

{
    "name": "4",
    "id": "beqvok",
    "img": "https://xx-xx.s3.amazonaws.com/demos/1491416271916",
    "url": "http://xxx/cms/demos",
    "tags": "ReactJS, NodeJS"
  }

How can I do so that if I delete ReactJS and NodeJS that have the id beqvok in the case of that demo instead of not showing up, show me something like this

{
    "name": "4",
    "id": "beqvok",
    "img": "https://xx-xx.s3.amazonaws.com/demos/1491416271916",
    "url": "xxx/cms/demos",
    "tags": "No Category"
  }
    
asked by Santiago D'Antuoni 05.04.2017 в 23:23
source

1 answer

0

try this

SELECT
  'i'.'name',
  'i'.'id',
  'i'.'img',
  'd'.'url',
  IFNULL(GROUP_CONCAT(t.name SEPARATOR ',"no category"), ') AS tags
FROM 'demos' i
  INNER JOIN 'details' d
    ON 'i'.'id' = 'd'.'demo_id'
  FULL OUTER JOIN tags t
    ON t.demo_id = i.id
GROUP BY 'i'.'id'
ORDER BY 'i'.'created_at'
  ASC

or with ...

LEFT OUTER JOIN en vez de FULL OUTER JOIN
    
answered by 07.04.2017 в 07:03