Subject | Help with SQL |
---|---|
Author | Fabio Gomes |
Post date | 2007-02-19T17:20:05Z |
Hi guys,
I have 2 tables, order and customer, i want to get a list with the
last 2 orders of each customer, but also (for pagination) I want to
get just 25 customers, how can i do it? So far I tried this:
SELECT * FROM order WHERE customer_id IN (SELECT FIRST 25 customer_id
FROM customer)
it works, but returns all the orders from my 25 customers, but i want
just 2 orders from each customer...
if i use: SELECT FIRST 2 * FROM order
It will just give me the last 2 orders, but i want to get 2 orders for
each customer.
Is there a way to do it without writing 2 queries?
Thanx in advance.
--
Fabio Gomes
I have 2 tables, order and customer, i want to get a list with the
last 2 orders of each customer, but also (for pagination) I want to
get just 25 customers, how can i do it? So far I tried this:
SELECT * FROM order WHERE customer_id IN (SELECT FIRST 25 customer_id
FROM customer)
it works, but returns all the orders from my 25 customers, but i want
just 2 orders from each customer...
if i use: SELECT FIRST 2 * FROM order
It will just give me the last 2 orders, but i want to get 2 orders for
each customer.
Is there a way to do it without writing 2 queries?
Thanx in advance.
--
Fabio Gomes