Subject | Problem with subselect and First |
---|---|
Author | Fabio Gomes |
Post date | 2007-02-21T16:37:46Z |
Hi, i have the following sql:
SELECT A.cli_cod, A.cxa_cod, A.cxa_data_rec, A.cxa_valor_recebido,
A.vnd_cod, C1.cli_nome, V.ved_nome
FROM caixa A
JOIN clientes C1 on (A.cli_cod=C1.cli_cod)
JOIN vendedores V on (C1.ved_cod=V.ved_cod)
WHERE
A.cxa_cod IN
(Select first 2 B.cxa_cod FROM caixa B WHERE B.cli_cod = A.cli_cod
ORDER BY B.cxa_cod DESC)
AND A.cli_cod IN
(select first 25 cli_cod from clientes ORDER BY cli_nome ASC)
AND cxa_data_rec IS NOT NULL
Order by C1.cli_nome ASC, A.cxa_data_rec DESC
I tested this query in my test server and it returns just 2 rows for
each customer (clientes), but then i tried it in the other server, and
it returns a lot of rows for each customer, it seens like it isn't
respecting the first 2 on this select:
(Select first 2 B.cxa_cod FROM caixa B WHERE B.cli_cod = A.cli_cod
ORDER BY B.cxa_cod DESC)
Both servers are running firebird 2, one is centos (the one the works)
and the other one is Ubuntu (it doesn't work here)
Anyone have any ideas why the Ubuntu server have this weird behavior?
Thanx in advance for any replies,
--
Fabio Gomes
SELECT A.cli_cod, A.cxa_cod, A.cxa_data_rec, A.cxa_valor_recebido,
A.vnd_cod, C1.cli_nome, V.ved_nome
FROM caixa A
JOIN clientes C1 on (A.cli_cod=C1.cli_cod)
JOIN vendedores V on (C1.ved_cod=V.ved_cod)
WHERE
A.cxa_cod IN
(Select first 2 B.cxa_cod FROM caixa B WHERE B.cli_cod = A.cli_cod
ORDER BY B.cxa_cod DESC)
AND A.cli_cod IN
(select first 25 cli_cod from clientes ORDER BY cli_nome ASC)
AND cxa_data_rec IS NOT NULL
Order by C1.cli_nome ASC, A.cxa_data_rec DESC
I tested this query in my test server and it returns just 2 rows for
each customer (clientes), but then i tried it in the other server, and
it returns a lot of rows for each customer, it seens like it isn't
respecting the first 2 on this select:
(Select first 2 B.cxa_cod FROM caixa B WHERE B.cli_cod = A.cli_cod
ORDER BY B.cxa_cod DESC)
Both servers are running firebird 2, one is centos (the one the works)
and the other one is Ubuntu (it doesn't work here)
Anyone have any ideas why the Ubuntu server have this weird behavior?
Thanx in advance for any replies,
--
Fabio Gomes