I have a terrible doubt.
I have a query like this:
SELECT id,fatherID FROM comments WHERE fatherID IS NULL
UNION
SELECT id,fatherID FROM comments WHERE fatherID IS NOT NULL
LIMIT 1
(Note the limit 1 applies to the union, not to only the second query)
(Note2: IS NULL, and IS NOT NULL are just an example, they can be a random string too)
With this limit 1 I am sure that this kind of query will return the row from the first query all the time?
Or even if both query returns something it can happen that the LIMIT 1 get the row coming from the second query?
I am asking this because If i run that query (wtihtou limit 1) I get this results
http://img856.imageshack.us/img856/5212/immaginejv.jpg
When I would except something like this (First all the rows with fatherid = null, then the other):
Order of returned results is (by default) undefined. If you want them ordered in a specific manner, use
ORDER BY, it was made to do exactly this.