May 18, 2007 at 9:02 am
How can I force a query to return all the joinable records from Table A, but only join the first matching record from Table B. Table A's primary key exists redudndantly in Table B as a foreign key. However, I need the first matching rec from B.
Thanks,
Almaz
May 18, 2007 at 9:56 am
You need to return the max row per id from table b in a derived table and then join that to table A. I would give more details but it's gonna take me sample data and table ddl. Also what do you consider to be the first record on table b?
May 18, 2007 at 11:50 am
Thanks much. I got the max and it did work. It really did not matter which one from the second table were selected, I just needed only one of them. There is redundant data in the second table. I don't manage the data, I just only query. Thanks a lot.
May 18, 2007 at 5:29 pm
Why not clean the data and make sure it stays clean forever, then simply doing a single join?
May 22, 2007 at 6:09 am
If you post the schema information or your final query, you may get some help making this perform better. I can think of two ways to write this that will cause SQL to perform an internal cursor operation, and at least one way that it probably will not. If you find your query slow, post it back here and you will probably get a landslide of options to speed it up.
Viewing 5 posts - 1 through 4 (of 4 total)
You must be logged in to reply to this topic. Login to reply