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

2011-12-05 Thread Rik Wasmus
Taking the question _very_ literal:

> A quick guess, or at least a starting point:
> 
> SELECT key, data

, SUBSTRING_INDEX(GROUP_CONCAT(data ORDER BY data SEPARATOR ','),',',2)

> FROM myTable
> GROUP BY key


-- 
Rik Wasmus

-- 
MySQL General Mailing List
For list archives: http://lists.mysql.com/mysql
To unsubscribe:http://lists.mysql.com/mysql



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 wrote:

> 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 | data 0-1
> Key 0 | data 0-2
> Key 1 | data 1-0
> Key 1 | data 1-1
>
> I want to select 2 data for each key.
> Key 0 (data 0-0, data 0-1), Key 1 (data 1-0, data 1-1).
>
> How to describe in query ?
>
> Best regards.
>


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 | data 0-1
Key 0 | data 0-2
Key 1 | data 1-0
Key 1 | data 1-1

I want to select 2 data for each key.
Key 0 (data 0-0, data 0-1), Key 1 (data 1-0, data 1-1).

How to describe in query ?

Best regards.


--- On Sat, 12/3/11, Govinda  wrote:

> From: Govinda 
> Subject: Re: delete syntax
> To: 
> Cc: mysql@lists.mysql.com
> Date: Saturday, December 3, 2011, 6:43 AM
> >> 
> >>> well, i am using delete/insert-statements
> since 10 years to maintain
> >>> users since you only have to know the tables
> in the database "mysql"
> >>> and use "flush privileges" after changes
> >>> 
> >>> The privileges should be maintained  only
> using the designated commands.
> >> You cannot rely on the knowledge you have of the
> underlying implementation
> >> which can change anytime , while the privileges
> command are standard.
> > 
> > do what you think is good for you if YOU can't be sure
> what you do
> > [snip]
> > so please do not tell other peopole on what knowledge
> they can rely
> > 
> 
> 
> *all* the back and forth in these threads is good.. is
> susses out all the knowledge for everyone to see.
> Sincerely thanks to everyone who chimes in from all
> perspectives,
> -Govinda
> --
> MySQL General Mailing List
> For list archives: http://lists.mysql.com/mysql
> To unsubscribe:    http://lists.mysql.com/mysql
> 
>

--
MySQL General Mailing List
For list archives: http://lists.mysql.com/mysql
To unsubscribe:http://lists.mysql.com/mysql