[thelist] MySQL

rudy Rudy_Limeback at maritimelife.ca
Mon Dec 18 11:14:46 CST 2000


> I need to select some rows from MySQL database 
> with each row having a unique value in the column 'aeg'.

hi lauri

sorry, this is not enough to go on, but i'll make a few guesses...

i shall assume the table contains multiple rows for each value of the aeg 
column, and that there's at least one other column, let's call it foo

   AEG   FOO
    1     aa
    1     bb
    2     xx
    3     mm
    3     pp
    3     rr

are you saying you only want one row for each distinct value of aeg? 

if you do not need the foo column, then here's the easiest way --

   SELECT DISTINCT aeg FROM yourTable

this will return one row per distinct aeg value

if you also need the foo column, and you only want one row per distinct 
aeg value, and you don't care which value of foo you get, you can use

     SELECT aeg, MIN(foo)  FROM yourTable
        GROUP BY aeg

this gives exactly one row per distinct value of aeg, along with the 
lowest value of the foo column for that aeg value

you can also use MAX(foo), AVG(foo), COUNT(*), and a bunch of other 
functions, including some that appear to be mysql extensions to standard 
sql -- see 
http://www.mysql.com/documentation/mysql/commented/manual.php?section=Group_by_functions


how were my guesses?

rudy.ca




More information about the thelist mailing list