Reputation: 700
Is there a difference between
SELECT * FROM my_table
and
SELECT my_column_id FROM my_table
where:
my_table
has million(s) of rowsin speed? Is it better to SELECT
just 1 column instead of * (all) for a rowCount()
query?
Upvotes: 0
Views: 70
Reputation: 36784
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....
O--O-------------O-------------O
|ID| my_col_1 | my_col_2 |
O--O-------------O-------------O
|0 | fskdjfh | jfkhgdkfj |
|1 | NULL | hfkjsdh |
|2 | jfkdhsdkjh | NULL |
|3 | fdfhkjh | NULL |
|4 | NULL | NULL |
O--O-------------O-------------O
SELECT COUNT(my_col_1)
will return 3
SELECT COUNT(my_col_2)
will return 2
SELECT COUNT(*)
will return 4
Upvotes: 2