snippetsqlMinor
How to avoid listing FIELD/IN twice?
Viewed 0 times
fieldtwiceavoidlistinghow
Problem
I have
SELECT field(foo,'this','that','bar','baz') FROM t WHERE f1 IN ('this','that','bar','baz') How can I avoid listing ('this','that','bar','baz') twice?Solution
Try using the FIELD function's return value and make sure it is not zero:
SELECT * FROM
(SELECT *,field(foo,'this','that','bar','baz') fieldfoo FROM t) A
WHERE fieldfoo > 0;Code Snippets
SELECT * FROM
(SELECT *,field(foo,'this','that','bar','baz') fieldfoo FROM t) A
WHERE fieldfoo > 0;Context
StackExchange Database Administrators Q#16546, answer score: 2
Revisions (0)
No revisions yet.