[SQL] Which SQL query makes it possible to optain the 3 greatest values of an interger list ?

2001-09-14 Thread Yoann

OO( Sql Problem )Oo. 

That is to say a table of 5 inputs of 1 integer field : 

   Table = { (1); (12); (3); (9); (4) }

We want to obtain a result of 1 input of 3 fields, 
corresponding to the 3 greatest values of Table, 
by descending order : 

   Result = { (12; 9; 4) } 

=> Which SQL query makes it possible to obtain Result from Table ?
We certainly need to use sub-queries, but how ?

Thank you in advance for your help !

Yoann AUBINEAU

---(end of broadcast)---
TIP 3: if posting/reading through Usenet, please send an appropriate
subscribe-nomail command to [EMAIL PROTECTED] so that your
message can get through to the mailing list cleanly



Re: [SQL] How do I extract ONE particular field, when multiple table contain the same field name?

2001-09-14 Thread Yoann

[EMAIL PROTECTED] (Olle Wijk) wrote in message 
news:<[EMAIL PROTECTED]>...
> Hi,
> 
> I am pretty new att using SQL-quires, could anyone help me with this
> one:
> 
> I want to do the following SQL-query:
> 
> Select XID, DENOM, PRICE, FRT, CTID From XItem xi, Category c Where
> xi.System=1 and xi.Category=c.Index
> 
> the problem is that the field 'DENOM' is present in both table 'XItem'
> and
> 'Category' (it is a text description field where you explain whatever
> you
> want). Therefore I get the following complaint when I run the query:
>  
> Error msg: "The specified fiel 'DENOM' could refer to more than one
> table listed
> in the FROM clause of your SQL-statement"
> 
> The DENOM-field I actually want is the one belonging to the
> XItem-table.
> I would most appreciate if someone could give me a hint how to alter
> the
> SELECT-statement above so that it does what I want.
> 
> Regards
> 
> /olw


When joinning tables, as you did, it's hardly recommended using
aliases, as you did too. (XItem <=> xi and Category <=> c). These
aliases can be used in all the SELECT statement including WHERE
clause, as you did again :), and SELECT clause. So, to refer to the
DENOM field from the table XItem, you should write :
xi.DENOM instead of DENOM alone. Your SELECT statement will be :

 Select XID, xi.DENOM, PRICE, FRT, CTID From XItem xi, Category c
Where
 xi.System=1 and xi.Category=c.Index

Notice than if you don't want to use aliases (what a wrong idea !),
you can write like the following :

 Select XID, XItem.DENOM, PRICE, FRT, CTID From XItem, Category Where
 XItem.System=1 and XItem.Category=Category.Index

Just some remarks about writing SQL statement.
it's preferabled (in my point of view) to :
 - write key words (like SELECT, FROM, WHERE, ...) in upper case
 - go to the next line when you change of key word
 - always use aliases
 - keep always the same alias for the same table in all the queries
 - write the fields in lower case
 - write the first lettre of a table name in upper, the rest in lower
case
 - use a "_ID" suffixe to the field name when it correspond to the
primary key of another table
 - name "ID" the primary key of a table

I would write your sql statement like :

 SELECT xi.ID, xi.denom, xi.price, xi.frt, cat.ID 
 FROM XItem AS xi, Category AS cat
 WHERE xi.system = 1 AND xi.category_ID = cat.ID;

good luck
Yoann

---(end of broadcast)---
TIP 3: if posting/reading through Usenet, please send an appropriate
subscribe-nomail command to [EMAIL PROTECTED] so that your
message can get through to the mailing list cleanly



[SQL] Number the lines

2001-09-14 Thread Yoann

how can I number the result's lines of a sql query ?

explaination : I have a query which return me a list of values. I need
to order them (it's ok, easy ;) and then number the lines. The goal is
then to extract, for example, "the third maximum value".

Tx in advance !
Yoann

---(end of broadcast)---
TIP 1: subscribe and unsubscribe commands go to [EMAIL PROTECTED]