I have one big query which is based on 12 smaller queries that I have put together using
A relative simple example of my query:
(SELECT 'type1' AS 'type', fieldOne AS someField, fieldTwo, fieldThree FROM tableOne JOIN users ON users.id = tableOne.id WHERE fieldFour = 'someValue' ) UNION (SELECT 'type2' AS 'type', fieldOne AS someField, fieldTwo, NULL AS fieldThree FROM tableTwo JOIN users ON users.id = tableTwo.id WHERE fieldFour = 'someValue' ) UNION ...
The query gets big since each of the 12 smaller queries need to have the same amount of fields, so I set many of the queries to NULL. This results in many reused lines throughout the queries. I must have the data in different tables in order to keep a good structure on things.
I think this can be made in a much more efficient way that is both smaller and takes less time to execute though I can't find any.