Home
Help
Search
Login
Register
February 10, 2012, 09:22:11 PM
Welcome,
Guest
. Please
login
or
register
.
1 Hour
1 Day
1 Week
1 Month
Forever
Login with username, password and session length
News
: Welcome to this forum
chang.advits.com
>
Database
>
Databases
(Moderator:
CK
) >
Any difference in these queries?
Pages: [
1
]
Go Down
« previous
next »
Print
Author
Topic: Any difference in these queries? (Read 652 times)
0 Members and 2 Guests are viewing this topic.
Chang Gee Guan
Administrator
Jr. Member
Karma: 0
Offline
Posts: 69
Any difference in these queries?
«
on:
July 09, 2008, 08:14:47 PM »
Let say i have a Table (Customer)
And i had written two queries:
i.
select cust_id, cust_name, cust_add, cust_age from Customer where cust_id>1000
ii.
select c.cust_id, c.cust_name, c.cust_add, c.cust_age from Customer c where cust_id>1000
These two queries will give the same output, but, they have differences in terms of performance.
Which 1 will perform better? Or they are just the same?
Logged
CK
Moderator
Newbie
Karma: 1
Offline
Posts: 11
Re: Any difference in these queries?
«
Reply #1 on:
July 09, 2008, 08:16:22 PM »
surely is the (ii) o
becoz AOA
Logged
Chang Gee Guan
Administrator
Jr. Member
Karma: 0
Offline
Posts: 69
Re: Any difference in these queries?
«
Reply #2 on:
July 09, 2008, 08:22:18 PM »
Quote from: CK on July 09, 2008, 08:16:22 PM
surely is the (ii) o
becoz AOA
because AOA??? hahahaha....
any more concrete answer why second query will run faster than the first 1?
Logged
CK
Moderator
Newbie
Karma: 1
Offline
Posts: 11
Re: Any difference in these queries?
«
Reply #3 on:
July 10, 2008, 08:44:07 AM »
what i ting is because the sql statement had create a alias table name for customer which is "c".
so when select stament "c.cust_id" is execute, it is faster compare to normal select statement "cust_id" which actually equally to "customer.cust_id" where it will search by the long table name "customer".
Logged
CK
Moderator
Newbie
Karma: 1
Offline
Posts: 11
Re: Any difference in these queries?
«
Reply #4 on:
July 10, 2008, 08:46:16 AM »
(i)SELECT city FROM country WHERE city!= 'Vancouver' AND city!= 'Toronto'; GROUP BY city;
(ii)SELECT city FROM country GROUP BY city HAVinG city!= 'Vancouver' AND city!= 'Toronto';
so, any idea which queries is faster,hehe
Logged
mysteriousdrx
Newbie
Karma: 0
Offline
Posts: 9
Re: Any difference in these queries?
«
Reply #5 on:
July 12, 2008, 02:14:13 PM »
which is faster?mm...i think that depends on your processor speed..haha
but i think its the first one..
Logged
CK
Moderator
Newbie
Karma: 1
Offline
Posts: 11
Re: Any difference in these queries?
«
Reply #6 on:
July 12, 2008, 04:04:29 PM »
Quote from: CK on July 10, 2008, 08:46:16 AM
(i)SELECT city FROM country WHERE city!= 'Vancouver' AND city!= 'Toronto'; GROUP BY city;
(ii)SELECT city FROM country GROUP BY city HAVinG city!= 'Vancouver' AND city!= 'Toronto';
so, any idea which queries is faster,hehe
the ans is avoid a HAVING clause in SELECT statements becoz it only filters selected rows after all the rows have been returned. Use HAVING only when summary operations applied to columns will be restricted by the clause. A WHERE clause may be more efficient.
Logged
Chang Gee Guan
Administrator
Jr. Member
Karma: 0
Offline
Posts: 69
Re: Any difference in these queries?
«
Reply #7 on:
July 13, 2008, 03:30:58 PM »
haha...
thanks for sharing these info.
hope it will help others to optimize their code.
Logged
Pages: [
1
]
Go Up
Print
« previous
next »
Jump to:
Please select a destination:
-----------------------------
General Category
-----------------------------
=> Admin
=> General Discussion
-----------------------------
Programming
-----------------------------
=> Java Discussion
=> C/C++ Discussion
=> Visual Basic/.Net
=> Others
-----------------------------
Web Programming
-----------------------------
=> Java Server Pages, JSP
=> Hypertext Preprocessor, PHP
=> Active Server Pages, ASP
=> Others
-----------------------------
Database
-----------------------------
=> Databases
-----------------------------
Multimedia
-----------------------------
=> Multmedia
-----------------------------
OS (Operating System)
-----------------------------
=> Windows
=> LINUX, UNIX
=> Others
-----------------------------
Network
-----------------------------
=> Networks
-----------------------------
Miscellaneous
-----------------------------
=> Jokes
=> Business
Loading...