is this join approach correct?

  • Hello, this is a really basic question but I haven't written SQL joining more than a few tables in a long time. Anyway, please consider the following:

    TableX

    -------

    X1

    X2

    X3

    TableY

    -------

    Y1

    Y2

    Y3

    I need to write a query with the following joins:

    TableX.X1 = TableY.Y1

    TableX.X2 = TableY.Y2

    What is the proper way to do this in SQL? Would it be:

    select x.*

    from TableX x

    join TableY y1 on y1.Y1 = x.X1

    join TableY y2 on y2.Y2 = x.X2

    Is there a more proper way to do this without creating multiple aliases of the same table?

  • Quick suggestion

    😎

    select x.*

    from TableX x

    join TableY y1 on y1.Y1 = x.X1

    and y1.Y2 = x.X2

  • that's it thanks!

Viewing 3 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic. Login to reply