I\'m frequently facing this issue, as an Oracle user, playing around with MySql.
Be the following situation:
Here is one way to do this using one query. It won't be the prettiest-formatted query, but it will be just one.
See my modified SQLFiddle.