0

Good day,

I have a practical mysql question to which I can't find help online.

Let's say I have a simple array of values "apple, pear, onion, ananas, banana, coconuts"

and that I would like to use mysql dynamically to, for example, sort, count or group those values.

Is it possible to do something like

SELECT COUNT FROM ("apple", "pear", "onion", "ananas", "banana", "coconuts")

? (of course I tried this and other syntaxes already, to no avail)

Basically what I'm trying to understand if it's possible to avoid creating a table for such a 'simple' task and set of values.

Thanks.

1 Answer 1

2

Not sure if shorter syntax exists:

SELECT COUNT(*) FROM (
SELECT "apple"
UNION SELECT "pear"
UNION SELECT "onion"
UNION SELECT "ananas"
UNION SELECT "banana"
UNION SELECT "coconuts" ) t
Sign up to request clarification or add additional context in comments.

1 Comment

UNION ALL will be slightly longer syntax but fractionally faster performance.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.