Subject Re: order by subselected value
Author Svein Erling Tysvær
Hi Michal!

You have to do ORDER BY <position>. Naturally, this is a bit dubious
when that position is after doing n.*, hence it would be safer to
change your query to

SELECT
(SELECT COUNT(*) FROM offers o WHERE o.nbid=n.id) offers,
n.*, (n.datefinish-CURRENT_TIMESTAMP)*{DAY} rest, n.article,
n.idealprice, c.name
FROM need n
join category c on c.id=n.catid
WHERE c.isactive=1
AND n.userid=?
AND CURRENT_TIMESTAMP BETWEEN n.datestart AND n.datefinish
ORDER BY 1;

HTH,
Set

--- In firebird-support@yahoogroups.com, Michal ®eravík wrote:
> Hi to all,
>
> I have got a little problem with this query:
> SELECT
> n.*, (n.datefinish-CURRENT_TIMESTAMP)*{DAY} rest, n.article,
> n.idealprice, c.name,
> (SELECT COUNT(*) FROM offers o WHERE o.nbid=n.id) offers
> FROM need n, category c
> WHERE
> c.id=n.catid AND c.isactive=1 AND n.userid=? AND
> CURRENT_TIMESTAMP>=n.datestart
> AND CURRENT_TIMESTAMP<=n.datefinish
> ORDER BY offers;
>
> and getting Dynamic SQL Error SQL error code = -206 Column unknown
> OFFERS.
> Is it possible to %subj%?
>
> thanx
> Michal