Reputation: 1520
For example I have a SELECT
query that returning result of two columns called ordered_zones
and available_zone
. Both results zone name like below
Expected result is result set to have one more column called non_matching_zone
. This column value should come from ordered_zones
by matching with available_zone
that is non-common values like below
Can I achieve above result with query itself?
Upvotes: 1
Views: 53
Reputation: 1520
Thank you all for your answers. My problem gets solved with mysql FIND_IN_SET
method by IF(NOT FIND_IN_SET(ordered_zone, available_zones), ordered_zone, "") AS non_matching_zone
.
Upvotes: 1
Reputation: 160
Assuming available_zone
always contain only one zone, you can replace available_zone
value in ordered_zones
with empty string
SELECT ordered_zones, available_zone, REPLACE(ordered_zones, available_zone, '') non_matching_zone
FROM table
Little work around is needed with commas, but that's the idea.
Upvotes: 0