Subject | Re: Selecting First Record |
---|---|
Author | Adam |
Post date | 2006-08-09T03:21:31Z |
--- In firebird-support@yahoogroups.com, "smeadsnz" <smeadsnz@...>
wrote:
MySQL lets you shoot yourself in the foot in many ways (or at least
did when I last played, Feb 30 was a nice date). It really does not
make sense to not include a non aggregate in a group by because it is
possible to get ambiguous results.
If you honestly don't care about which of the ambiguous other fields
that do not appear in the group by, use min for those fields too.
Or try something like
SELECT *
FROM T1
WHERE ID = (select max(T2.ID) FROM T2)
Adam
wrote:
>be
> Hi,
>
> I am having a problem with the firebird sql in that there seems to
> no way to group records by only one non-aggregate field. Forexample,
> take the following 2 tables:table
>
> t1(
> id int pkey,
> code string,
> public_no int
> )
>
> t2(
> id int references t1(id),
> add_date datetime,
> some_value
> primary key(table1_id, add_date)
> )
>
> now, table 2 can have multiple records added for each record of
> 1. There seems to be no way to fetch a list of distinct recordsfrom
> table 1 matched to only the latest record of table 2, any join youdo
> will produce a new row for each record of table 2, so you aregetting
> all records instead of the latest.containing
>
> I'm used to MySql, you'd just need to add a group by clause
> only t1.id and it would work, but Firebird makes you add everysingle
> non-aggregate to the group by, making it pointless. Some otherdbms's
> have a First() function which I am sure would do the trick.What SQL did you expect to work?
>
> Does anybody know of a solution to this?
>
MySQL lets you shoot yourself in the foot in many ways (or at least
did when I last played, Feb 30 was a nice date). It really does not
make sense to not include a non aggregate in a group by because it is
possible to get ambiguous results.
If you honestly don't care about which of the ambiguous other fields
that do not appear in the group by, use min for those fields too.
Or try something like
SELECT *
FROM T1
WHERE ID = (select max(T2.ID) FROM T2)
Adam