Is there a difference between
SELECT * FROM my_table
and
SELECT my_column_id FROM my_table
where:
my_tablehas million(s) of rows- there are a lot of concurrent users doing sql queries on the website
in speed? Is it better to SELECT just 1 column instead of * (all) for a rowCount() query?
Of course theres a difference.
SELECT * FROM my_table– Select all column’s worth of data (whole table).SELECT my_column_id FROM my_table– Select one column’s worth of data.Its common sense really.. More data.. More time.
But @Juhana makes a good point. If your just counting rows, use
SELECT COUNT(*)For the sake of your comment….
SELECT COUNT(my_col_1)will return 3SELECT COUNT(my_col_2)will return 2SELECT COUNT(*)will return 4