How to get a specific number of entries per one key ?

2011-12-03 Thread Blog Tieng Viet
Hellow everybody. I have a problem difficult for me, please give me an advice. I want to get a specific number of entry (rows) from a table by each Key. If the number is 1, I can use select dinstinct, but the number is not 1, I don't know how to select. For example: Key 0 | data 0-0 Key 0 |

Re: How to get a specific number of entries per one key ?

2011-12-03 Thread Arthur Fuller
A quick guess, or at least a starting point: SELECT key, data FROM myTable GROUP BY key LIMIT 2 HTH, Arthur On Sat, Dec 3, 2011 at 11:41 AM, Blog Tieng Viet blogtiengv...@yahoo.comwrote: Hellow everybody. I have a problem difficult for me, please give me an advice. I want to get a

Query query

2011-12-03 Thread Jan Steinman
I'm having brain freeze, and wonder if anyone can help me with a query. I have a library in MySQL. There's a table with a record per book, and other tables that it indexes into for meaningful info. One of those is an integer-keyed list of 1,000 Dewey Decimal Codes. In the books table, the Dewey

Re: Query query

2011-12-03 Thread Jan Steinman
Second attempt, using a join, returns just one row for Dewey 000 with the COUNT being about half the volumes in the library, which isn't right... I thought a LEFT OUTER JOIN would have returned a record for every record in s_library_dewey, but it only returns the first. Brain freeze again...

Re: Query query

2011-12-03 Thread Peter Brawley
On 12/3/2011 9:35 PM, Jan Steinman wrote: Second attempt, using a join, returns just one row for Dewey 000 with the COUNT being about half the volumes in the library, which isn't right... I thought a LEFT OUTER JOIN would have returned a record for every record in s_library_dewey, but it only

Re: Query query

2011-12-03 Thread Jan Steinman
DOH! Brain unfroze, and I realized I needed an aggregate: SELECT COUNT(lib.Dewey) AS Have, ddn.Dewey AS DDN, ddn.Classification AS Classification FROM s_library_dewey ddn LEFT OUTER JOIN s_library lib ON ddn.Dewey = FLOOR(lib.Dewey) WHERE 1 GROUP BY ddn.Dewey ... although if there