Reply to Re: Get one row from each group of rows

Your name:

Reply:


Posted by M A Srinivas on 07/23/07 06:35

On Jul 22, 9:19 am, deluca.vice...@gmail.com wrote:
> Hi,
>
> I'm trying to build a query that get only one row from a group of
> rows, but I need the values from that row and not the results of one
> function group.
> I need one row for each idRef, with column2=2 and the bigger column1
>
> id |idRef | column1 | column2
> 1 1 0 1
> 2 1 1 2
> 3 1 2 1
> 4 2 0 1
> 5 2 1 2
> 6 2 2 1
> 7 2 3 2
>
> For these, I will take the rows with id=2 and id=7.
>
> Thank you, and sory for my english.

select a.* from tbl a
join
(select idref,max(column1) as column1
from tbl
where column2 = 2
group by idref) as b
on a.idref = b.idref
and a.column1 = b.column1

[Back to original message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация