Re: fetch row DISTINCT

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Lars,

One idea that occurs to me, and it's a tradeoff from Torsten's idea (which
is to read the whole database, and parse out the unique rows), is to first
execute your "SELECT DISTINCT distinct_col FROM table", and then walk
through that, and for each one issue a "SELECT * FROM table WHERE
distinct_col = {value} LIMIT 1"  (For some reason I can't remember the
'LIMIT' syntax right now, so it might be LIMIT 0,1).  More transactions with
the database, but less data actually retrieved from the database.  And if
it's indexed by distinct_col, you should be fine.

Added benefit:  you can apply arbitrary ORDER BY mechanisms to the
individual queries... so it will only show you the most recent, or the
first, or a random entry... all up to you.

-P

---- Original Message
"Lars Hilsebein" <lars.hilsebein@xxxxxxxxxxxxxx> wrote in message
news:60D21430A600D61193B30050DA5C4E370F1F37@xxxxxxxxx
Sorry, but it's not truly what I am searching for:
The result is not unique.
What I mean is: every entry in the distinct_col should only be delivered
once.
As it would happen when I do the query "SELECT DISTINCT distinct_col FROM
table".
But I need to fetch the whole row.

Lars

-- 
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [PHP Users]     [Postgresql Discussion]     [Kernel Newbies]     [Postgresql]     [Yosemite News]

  Powered by Linux