This question has just came in to my mind, and I'm not in a position to answer it.
Let's say you are developing a news page for a website. In your table you would have the following fields:
ID, Title, Subject, Content, Time, Author, Keywords
On the actual page that the user will see, you may only want to display the following:
Title, Content, Keywords
Now, when you go to write the SQL statement, would it be better to write it as this:
SELECT Title, Content, Keywords FROM newstable;
Or as this:
SELECT * FROM newstable;
I always thought that using the former example would be far more efficient and quicker to use. However, I'm now thinking it might be quicker and easier to just use the select all statement.
Is either way right, or does it really matter how they are written?
SELECT column returns only the value of that column. SELECT * returns the value of every column in the table.
That's all about why you should not use SELECT * in the SQL query anymore. It's always better to use the explicit column list in the SELECT query than a * wildcard. It not only improves the performance but also makes your code more explicit.
Selecting distinct and less than all columns will always be faster than selecting *.
Yes, it matters for performance and other reasons.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With