Is SELECT * always inadvisable in MySQL?

I have often seen on here the advice to avoid SELECT * in SQL queries. In terms of making MySQL queries in PHP, if I do actually want the result to contain every column is there any disadvantage in using SELECT * rather then typing out all the column names?

Thank you.

1 Like

You could always use an array and do something like the following:

implode(", ", array_keys($data))

that way you can control what columns are read in by the HTML form or by some other means.

only maintainability

if you ever add another column to the table, then “select star” will automatically pick it up, and your code may not handle the results properly

but there’s no technical reason why coding all the column names is better than “select star” if you do really want all columns

4 Likes

It is also a question of readable code.

When you only write select *, you do not know what you are retrieving. You have to look at the table structure in your database management tool first.

3 Likes

Thank you all.