PLEASE SEE THE LAST EDIT ON THE BOTTOM
I have the following query using MySQL in phpMyAdmin:
(SELECT
id,
name,
rank1,
rank2
FROM rank_list
LEFT JOIN names ON names.id = rank_list.name_id
WHERE type = "typeA"
ORDER BY rank1
LIMIT 50)
UNION ALL
(SELECT
id,
name,
rank1,
rank2
FROM rank_list
LEFT JOIN names ON names.id = rank_list.name_id
WHERE type = "typeB"
ORDER BY rank2
LIMIT 50)
- What it does is to get the top 50 ranks for
rank1
oftypeA
and merge it with top 50 ranks forrank2
oftypeB
. - I need to use parentheses around each sub
SELECT
because I apply a
LIMIT
andORDER BY
statement to both. - Both individually are working fine.
PROBLEM
I am getting the following error when applying the UNION
to both queries:
A non-numeric value encountered
I really don’t get it here… One thing that might cause this is that I fill rank1
column -1
if type = "typeB"
(same for rank2
and type = "typeA"
.
Or is it something else here?
EDIT:
It does work when I don’t apply a LIMIT
to it
EDIT 2
I figured out that when doing the following (using parentheses) I also get the same error:
(SELECT id FROM rank_list LIMIT 1)
2
Answers
try enfor the data type using a cast
I cannot reproduce your issue
Note I have fully qualified id, If your model is different then without more input from you any answer or comment will be guesswork.