Subject | Firebird 2.5: Nested querys help |
---|---|
Author | |
Post date | 2017-08-31T14:46:24Z |
Hi to all.
I have a table with these columns:
table_id, date_time, customer, other_fields
One customer could have several records in the same date and I have to make a SELECT only to the first table_id for a given date for each customer_id. I have worked around the query with something like this but I haven't succeed:
SELECT
xx0.table_id
FROM
my_table xx0
WHERE
xx0.date_time >= CAST('today' AS DATE) + 1
AND xx0.date_time < CAST('today' AS DATE) + 2
AND xx0.table_id IN (
SELECT FIRST 1
xx2.table_id
FROM
my_table xx2
WHERE
xx2.date_time >= CAST('today' AS DATE) + 1
AND xx2.date_time < CAST('today' AS DATE) + 2
AND xx2.customer_id IN (
SELECT DISTINCT
xx1.customer_id
FROM
my_table xx1
WHERE
xx1.date_time >= CAST('today' AS DATE) + 1
AND xx1.date_time < CAST('today' AS DATE) + 2
)
ORDER BY
xx2.date_time
)
ORDER BY
xx0.date_time
Any help will be appreciated.
Best regards,
Hernando.