Query to Join Table to Itself with a Filter

Posts   
 
    
psandler
User
Posts: 540
Joined: 22-Feb-2005
# Posted on: 12-May-2006 18:18:46   

I'm trying to join a table to itself, where no join exists in the database. The join will be based on a few specific criteria. Since no relation exists, I'm not sure how to create the join in my dynamic typed list. I also haven't used LLBLGen for a while (the good news is: we are using it on several new projects now smile smile smile smile smile ).

I'm about 90% sure that I am not thinking about this correctly, and that I can accomplish the same thing with a subquery.

Here is my current query. Basically I want to count similar events that happened previous to the current event (and include the current in the count). I had to change some names because it's a client project. Hoepfully it still makes sense.


    SELECT
        COUNT(t2.transactioneventid) count
    FROM
        TransactionEvent t1
        INNER JOIN TransactionEvent t2 ON 
            (t2.transactioneventdate <= t1.transactioneventdate 
            AND t2.transactioneventtype = t1.transactioneventtype
            AND t2.otherId = t1.otherId)
    WHERE
        t1.transactioneventid = 123456

Thanks for any help.

psandler
User
Posts: 540
Joined: 22-Feb-2005
# Posted on: 15-May-2006 23:30:33   

Any thoughts on this?

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39928
Joined: 17-Aug-2003
# Posted on: 16-May-2006 09:42:06   

Sorry for the delay, it must have slipped through the cracks.

A join which isn't present as a relation can be done by creating a new EntityRelation object. You then add the fields participating in that relation to the EntityRelation and add that to a RelationCollection (or bucket.Relations) as you'd do otherwise. Please see one of the generated Relations classes for ideas how to create your own EntityRelation object. You don't need to add inheritance info as its done in the generated relation classes.

Frans Bouma | Lead developer LLBLGen Pro