>I have a table with one ID-Column and one Sort-Column.
>
>I need the ID from the record with the lowest sort-number.
>Sortnumbers are not unique (can be doubled).
>
>Can I do this with one SQL-Statement?

If you want one row returned:

Select ID_column
From <Table>
Order by Sort_Column
Rows 1

If you want all rows returned:

Select ID_column
From <Table> t1
Where not exists(select * from <Table> t2 where t1.Sort > t2.Sort)

Alternatively, you could use

With tmp(Sort) as
(select min(Sort) from <table>)
Select t.ID_Column
From tmp
Join <table> t on tmp.Sort = t.Sort

Set
  • ... josef.gschwendt...@quattro-soft.de [firebird-support]
    • ... Helen Borrie hele...@iinet.net.au [firebird-support]
    • ... Svein Erling Tysvær svein.erling.tysv...@kreftregisteret.no [firebird-support]
      • ... josef.gschwendt...@quattro-soft.de [firebird-support]
    • ... liviuslivius liviusliv...@poczta.onet.pl [firebird-support]

Reply via email to