0
Which query is Faster and why? Their results is same.
SELECT * FROM MyTable; SELECT * FROM MyTable WHERE ID > 0
5 Réponses
+ 3
I think unless you have records having ID field value less than or equal to zero these queries will fetch the same amount of data, meaning they carry equally weighed task, none is any faster than the other.
+ 3
What if no record was found to match the condition? or the other way around, if all records match the condition?
Logically, when a secretary was asked to collect all the clients' files, she gets them all faster than if she was told to collect clients' files with a condition, where she checks each file to verify whether the file match the required condition. It doesn't differ that much with how database server works in filtering data IMHO.
+ 2
Not if your table has records having `ID` field value less than or equal to zero. When you set a condition it means there are evaluation done on each record to filter out records that match criteria. Evaluation means extra work, which means more time.
+ 1
Without condition you take all data table, also it not use id for getting data. Condition help you to get faster.
0
Second is faster then first coz one or more condition makes query faster