Re: simple SQL query problem
Date: 1995/09/25
Message-ID: <dlm3-2509951828180001_at_wyndmoor1-57.slip.netaxs.com>#1/1
In article <DF78Bq.99I_at_news.cern.ch>, Maria.SKIADELLI_at_cern.ch (Maria SKIADELLI) wrote:
> Hello there,
> is there anybody that knows how can I select using an SQL statement
> only one member-record of a set that matches a certrain condition,
> (no matter which one)?
>
> Thanks
> Maria Skiadelli
> CERN AT/IC
> mskiadel_at_cernvm.cern.ch
Is this a correlated query, or just a straight select <fields> from <table> where <condition> ?
If it's the latter, I know the following works fine:
select <fields> from <table> where <condition> and rownum < 2;
the rownum pseudo-field is generated for every query and provides an ordinal number for each row returned (see the SQL reference manual).
With a correlated query, i.e., the condition is a
where field = (select <field> from <table>)
statement, it gets a little hairy. As I recall the rownum trick works, but it doesn't work well if there's an 'order by' clause in the statement.
don mccorvey
aka mccorveyd_at_pgate.he.boeing.com
dba at large
Vehicle Management Systems Design
Boeing Defense&Space Group
Helicopters Divisision
don mccorvey | dlm3_at_netaxs.com | Philadelphia, PA
"A human being should be able to change a diaper, plan an invasion, butcher a hog, conn a ship, design a building, write a sonnet, balance accounts, build a wall, set a bone, comfort the dying, take orders, give orders, cooperate, act alone, solve equations, analyze a new problem, pitch manure, program a computer, cook a tasty meal, fight efficiently, die gallantly. Specialization is for insects.
- Robert A. Heinlein