Optimizing a query

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

User avatar
shiznatix
DevNet Master
Posts: 2745
Joined: Tue Dec 28, 2004 5:57 pm
Location: Tallinn, Estonia
Contact:

Re: Optimizing a query

Post by shiznatix »

Gosh, sorry, I was being really stupid for a minute there. I was using a limit/offset that wouldn't be including the first result and then I was wondering why it wasn't working.

I think I am all patched up over here. Thank you Weirdan and Mikosiko - your help is greatly appreciated.
x_mutatis_mutandis_x
Forum Contributor
Posts: 160
Joined: Tue Apr 17, 2012 12:57 pm

Re: Optimizing a query

Post by x_mutatis_mutandis_x »

I just noticed as to why there is a "DISTINCT COUNT(companies.companyid )" in your query? Instead just do "SELECT COUNT(companies.companyid ) ", it should always return 1 row
User avatar
Weirdan
Moderator
Posts: 5978
Joined: Mon Nov 03, 2003 6:13 pm
Location: Odessa, Ukraine

Re: Optimizing a query

Post by Weirdan »

shiznatix must have meant count(distinct companies.companyid) (which is, of course, different from distinct count(companyid))
x_mutatis_mutandis_x
Forum Contributor
Posts: 160
Joined: Tue Apr 17, 2012 12:57 pm

Re: Optimizing a query

Post by x_mutatis_mutandis_x »

Weirdan wrote:shiznatix must have meant count(distinct companies.companyid) (which is, of course, different from distinct count(companyid))
Ahh then its ok, but from my experience, I tried to avoid using distinct as it usually forces the query to use a temp table and gets really slow
User avatar
shiznatix
DevNet Master
Posts: 2745
Joined: Tue Dec 28, 2004 5:57 pm
Location: Tallinn, Estonia
Contact:

Re: Optimizing a query

Post by shiznatix »

Edit: ignore me.
Post Reply