Search code examples
mysqlinformation-schema

Reverse filter for SQL show query. "Show Fields from xtable where Field = xFieldnameA = a AND Field = xFieldnameB


This concerns sql show queries. The following query below works the issue is it seems I must tell mysql which field names I don't want rather than those I do (which is preferred).

e.g. (working)

SHOW FIELDS FROM users WHERE Field != 'uid' AND Field != 'fk_Utype'

The above executes perfectly as expected, stipping off both 'uid' and 'fk_Utype' from the result set. However when querying by which columns I only want (like a traditional Select query) listing the column names needed does not behave as expected.

SHOW FIELDS FROM users WHERE Field = 'firstName' AND Field = 'lastName'

I expected the above query to simply return the two specified columns. However, the query instead results in an empty result set (the columns do exist in that table and appear when the above query is executed). Clearly I'm not listing the desired column names correctly. As in a Select statement the syntax it simply 'Select col1, col2' but this syntax is incorrect in a SHOW query (though I may well be mistaken).


Solution

  • SHOW FIELDS FROM users WHERE Field = 'firstName' OR Field = 'lastName'
    

    AND means both conditions must be true whereas OR means either condition can be true.