SubSonic Forums
All Your Database Are Belong To Us

Self join

Latest post 10-21-2008 11:10 PM by ranomore. 6 replies.
  • 09-25-2008 5:50 AM

    Self join

    Hi all,

    How do you do a self join in SubSonic using the new query object?

    Here is the SQL I want to produce

    SELECT     Page.ProductId, Page.PageTitle, Page.PageDescription, Page.InActive, Page.NextPageId AS NextPage, Page_1.PageTitle AS NextPageTitle
    FROM         Page LEFT OUTER JOIN Page Page_1 ON Page.NextPageId = Page_1.Id

    I do not know how you set the alias for the Table name, below is what I cribbed together

    ProductBuilder.DB.Select("ProductId",
                                     "PageTitle",
                                     "InActive",
                                     "Page.NextPageId AS NextPage", "Page_1.PageTitle AS NextPageTitle").From("Page").
                                     LeftOuterJoin(ProductBuilder.Page.IdColumn,ProductBuilder.Page.NextPageIdColumn).ExecuteDataSet();

     

    Thanks

    Northern

     

  • 09-28-2008 5:12 PM In reply to

    Re: Self join

    I don't think this is possible with SqlQuery you might have to use InlineQuery for this :(

    If I am I because I am I, and You are You because You are You, then I am I, and you are you. But If I am I because You are You, and You are You because I am I, then I am not I and You are not You. -Rabbi of Kotzk

  • 09-29-2008 5:57 PM In reply to

    Re: Self join

    Cheers, I will use the inline.

     

    Thanks

  • 09-30-2008 3:37 AM In reply to

    Re: Self join

    Yeah, it is not possible, but it's a common scenario in SQL and I've been asking for the same for a couple of months. Table alias feature would be great.

  • 10-17-2008 3:54 AM In reply to

    • dhigginx
    • Top 500 Contributor
    • Joined on 02-06-2008
    • California
    • Posts 10

    Re: Self join

     I offered code for aliasing tables back in March but either the powers that be didn't see my post or they rejected the concept as unnecessary.

    -Dennis

     

  • 10-18-2008 2:59 PM In reply to

    Re: Self join

    Can you post the patch. Thanks Northernmonkey2000

  • 10-21-2008 11:10 PM In reply to

    • ranomore
    • Top 10 Contributor
    • Joined on 11-05-2007
    • Salt Lake City
    • Posts 322

    Re: Self join

    dhigginx:
    I offered code for aliasing tables back in March but either the powers that be didn't see my post or they rejected the concept as unnecessary.

    Probably the former--especially if it was a forum post (not codeplex).

Page 1 of 1 (7 items) | RSS