Is there any way to select columns with wild cards.
like
to select columns with names having type could be ‘SELECT %type% from table_name‘ ?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Not really. You can use the
*column wildcard to select all columns. If you’re joining multiple tables, you can select all columns from specific table by prefixing*with the table name or alias:However, you shouldn’t use
*unless you’re writing a DB administration program.Alternatively, you can build a statement within SQL or another language by fetching table metadata to get the column names. Using just MySQL, you can query the
COLUMNStable in theINFORMATION_SCHEMAdatabase to get the column names and useGROUP_CONCATto build the column list for the statement.Replace “:db”, “:table” and “…” with the appropriate values. You can even turn it into a prepared statement so you can use it for any table. From there,
PREPAREandEXECUTEthe constructed statement.If you’re not limited to SQL for programming, it should be less messy. The DB driver for your language of choice likely offers methods to get metadata. The actual implementation would be similar to the pure SQL approach (get column names, assemble statement, prepare, execute), but shouldn’t be so ugly, as you’d be using an algorithmic, rather than declarative, language.
I would be very interested in seeing the situation that this is actually required..