Optimizing GROUP BY and ORDER BY

2008-07-25 Thread Michael Stearne
I have a query: SELECT Country, COUNT( Country ) AS Cnt FROM properties WHERE ( Country != 'USA' AND Country != 'US' AND Country != 'Unit' AND Country != 'United States' AND Country != ' ' AND Country IS NOT NULL ) GROUP BY Country ORDER BY Cnt DESC LIMIT 8 that gets the top 8 non-US countries

Re: Optimizing GROUP BY and ORDER BY

2008-07-25 Thread Rob Wultsch
!= ' ' AND Country IS NOT NULL ) GROUP BY Country ORDER BY Cnt DESC LIMIT This is a costly query I suggest that this is not a well normalized. I suggest that at a minium you should be using a 'Country' which would include a distinct entry for each country. If such a table exists a column

Re: Optimizing GROUP BY and ORDER BY

2008-07-25 Thread Michael Stearne
25, 2008 at 4:27 AM, Michael Stearne [EMAIL PROTECTED] wrote: I have a query: SELECT Country, COUNT( Country ) AS Cnt FROM properties WHERE ( Country != 'USA' AND Country != 'US' AND Country != 'Unit' AND Country != 'United States' AND Country != ' ' AND Country IS NOT NULL ) GROUP

Optimization on query with WHERE, GROUP BY and ORDER BY

2003-12-05 Thread Martin Gillström
Hi, I have a table with about 500 000 rows and need to execute a query with first a WHERE then a GROUP BY and then ORDER BY all on different columns is their any way to optimize this? The table can look something like this: row_id INT PRIMARY KEY where_column SET('a','b','c') groupby_column

Re: Optimization on query with WHERE, GROUP BY and ORDER BY

2003-12-05 Thread Chris Elsworth
Hello, On Fri, Dec 05, 2003 at 12:02:05PM +0100, Martin Gillstr?m wrote: The table can look something like this: row_id INT PRIMARY KEY where_column SET('a','b','c') groupby_column VARCHAR(255) orderby_column DATE .. more rows that I need to fetch with the select. This is what I have

GROUP BY and ORDER BY not working together

2003-05-29 Thread Peter Fleck
, dates.subdaynum FROM grants, dates WHERE (grants.agency = NIH-O AND grants.grantid = dates.grantid) GROUP BY grants.grantid ORDER BY dates.yearday; This gives me one listing per grant but they are not sorted correctly. From what I can figure out, mysql is only looking at the first occurence of a grant

Re: GROUP BY and ORDER BY not working together

2003-05-29 Thread James Moe
(grants.agency = NIH-O AND grants.grantid = dates.grantid) GROUP BY grants.grantid ORDER BY dates.yearday; The results are sorted within the groups by yearday. However, the groups themselves are not in any particular order. Try this: order by grants.grantid,dates.yearday; - -- jimoe

Re: GROUP BY and ORDER BY not working together

2003-05-29 Thread Keith C. Ivey
On 28 May 2003 at 14:17, Peter Fleck wrote: SELECT grants.grantid, grants.refnum, dates.subdaynum FROM grants, dates WHERE (grants.agency = NIH-O AND grants.grantid = dates.grantid) GROUP BY grants.grantid ORDER BY dates.yearday; This gives me one listing per grant

Re: GROUP BY and ORDER BY not working together

2003-05-29 Thread Peter Fleck
At 3:50 PM -0400 5/28/03, Keith C. Ivey wrote: On 28 May 2003 at 14:17, Peter Fleck wrote: SELECT grants.grantid, grants.refnum, dates.subdaynum FROM grants, dates WHERE (grants.agency = NIH-O AND grants.grantid = dates.grantid) GROUP BY grants.grantid ORDER BY dates.yearday

Re: query problem with GROUP BY and ORDER BY

2002-06-02 Thread Philip Spradling
I need to get a list in alphabetical order, but with people in the same apt keept together: Brant, Svensen Doe Smith, Smith The difficulty is to get people living in the same apt grouped together. SELECT * FROM tbl GROUP BY apt ORDER BY name - will drop the second name found

query problem with GROUP BY and ORDER BY

2002-06-01 Thread Claire Forchheimer
, Svensen Doe Smith, Smith The difficulty is to get people living in the same apt grouped together. SELECT * FROM tbl GROUP BY apt ORDER BY name - will drop the second name found in each apt! (The result would be this list: Brant Doe Smith) I've been banging my head black and blue over this query

Re: group by and order by

2001-05-14 Thread Bob Hall
I have a table with texts, all of different type, I have field named type to know which is which. What I would want is with one SQL query select the latest from each type, but this query... select id, headline, type from texts group by type order by date; will give the first of each type. I

group by and order by

2001-05-11 Thread Sandman
I have a table with texts, all of different type, I have field named type to know which is which. What I would want is with one SQL query select the latest from each type, but this query... select id, headline, type from texts group by type order by date; will give the first of each type. I