Board index » delphi » I need Your Help ( SQL Statement )

I need Your Help ( SQL Statement )

Dear Friends

Please guide me that how I can Use SQL statement to find The first Row in
database that Match My Criteria for example if  I
write  " Select   ( Required Fields Name ) from  (Table Name) Where ( Field
Name ) >=1000 "  all of the rows those meet the criteria will be select ,
But
I want to extract the first row in the table that meet ( S>=1000) What
should I add to SQL statement ???

Regards;
Ali

 

Re:I need Your Help ( SQL Statement )


Try something like this:

select * from mytable
where uniquefield =
  (select min(uniquefield) from mytable where selectfield >= 1000)

Christopher Latta

Ali Reza Setoodeh <Setood...@Yahoo.com> wrote in message
news:3bef61e9_2@dnews...

Quote
> Please guide me that how I can Use SQL statement to find The first Row in
> database that Match My Criteria for example if  I
> write  " Select   ( Required Fields Name ) from  (Table Name) Where
 Field
> Name ) >=1000 "  all of the rows those meet the criteria will be select ,
> But
> I want to extract the first row in the table that meet ( S>=1000) What
> should I add to SQL statement ???

Re:I need Your Help ( SQL Statement )


If your database supports it, you can use SELECT FIRST FieldName FROM
TableName ... or SELECT TOP 1 FieldName FROM TableName .... (Those
statements work in SQL Anywhere but I don't know how standard they are.)
Presumably, your SELECT statement includes an ORDER BY OrderField clause so
you get the one record you want.

If your server does not support SELECT FIRST or SELECT TOP, you can use
SELECT FieldName FROM TableName WHERE Field >= 1000 and OrderField = (SELECT
MIN(OrderField) FROM TableName WHERE Field >= 1000). Note that this query
will return more than one row if more than one row has the minimum value of
OrderField.

  Richard

"Ali Reza Setoodeh" <Setood...@Yahoo.com> wrote in message
news:3bef61e9_2@dnews...

Quote

> Please guide me that how I can Use SQL statement to find The first Row in
> database that Match My Criteria for example if  I
> write  " Select   ( Required Fields Name ) from  (Table Name) Where (
Field
> Name ) >=1000 "  all of the rows those meet the criteria will be select ,
> But
> I want to extract the first row in the table that meet ( S>=1000) What
> should I add to SQL statement ???

Re:I need Your Help ( SQL Statement )


"Ali Reza Setoodeh" <Setood...@Yahoo.com> wrote in message
news:3bef61e9_2@dnews...

Quote
> Dear Friends

> Please guide me that how I can Use SQL statement to find The first Row in
> database that Match My Criteria for example if  I
> write  " Select   ( Required Fields Name ) from  (Table Name) Where (
Field
> Name ) >=1000 "  all of the rows those meet the criteria will be select ,
> But
> I want to extract the first row in the table that meet ( S>=1000) What
> should I add to SQL statement ???

> Regards;
> Ali

simply add ' ORDER BY [id field] ASC LIMIT 1' to the end of your statement.

Other Threads