-1
  SELECT a.*

  FROM tableA AS a

  LEFT JOIN tableC AS c
  ON c.id = a.catid

  LEFT JOIN tableD AS d
  ON d.id = a.created_by

  INNER JOIN tableE AS e
  ON e.content_id = a.id

  WHERE a.access IN (1,1,5)
  AND c.access IN (1,1,5)

I am trying to use UNION ALL/ UNION operation instead of IN operation in SQL. I am having troubles to figure out how to convert the above query to use UNION. How Can I convert the above query to use UNION

Popnoodles
  • 28,090
  • 2
  • 45
  • 53
Nadeeshaan
  • 356
  • 5
  • 15

1 Answers1

0

Maybe you need something like this:

(
SELECT a.*
FROM tableA AS a
LEFT JOIN tableC AS c
ON c.id = a.catid
WHERE a.access = 1
AND c.access = 1
)

UNION ALL

(
SELECT a.*
FROM tableA AS a
LEFT JOIN tableC AS c
ON c.id = a.catid
WHERE a.access = 5
AND c.access = 5
)

UNION ALL

(
SELECT a.*
FROM tableA AS a
LEFT JOIN tableD AS d
ON d.id = a.created_by
INNER JOIN tableE AS e
ON e.content_id = a.id
)
Dusan
  • 791
  • 5
  • 16