Loading ...
Sorry, an error occurred while loading the content.

Inner join or join one table to 2 other

Expand Messages
  • Tony Trapp
    Hey guys need some help, I know how to do inner join one table to another but how do I do one table joined on two tables? They of course all have an ID in
    Message 1 of 7 , Jun 5, 2008
    • 0 Attachment
      Hey guys need some help, I know how to do inner join one table to
      another but how do I do one table joined on two tables?

      They of course all have an ID in common.

      I already did a search on google too no help that I could find.

      I am using sql server 2005 enterprise edtion

      Thanks guys.
    • John Warner
      What exactly do you mean, I m not clear here at all? Maybe if you list a few fields from each table and then tell us what result you are seeking. John Warner
      Message 2 of 7 , Jun 6, 2008
      • 0 Attachment
        What exactly do you mean, I'm not clear here at all? Maybe if you list a
        few fields from each table and then tell us what result you are seeking.

        John Warner

        > -----Original Message-----
        > From: SQLQueriesNoCode@yahoogroups.com
        > [mailto:SQLQueriesNoCode@yahoogroups.com] On Behalf Of Tony Trapp
        > Sent: Thursday, June 05, 2008 6:20 PM
        > To: SQLQueriesNoCode@yahoogroups.com
        > Subject: [SQLQueriesNoCode] Inner join or join one table to 2 other
        >
        > Hey guys need some help, I know how to do inner join one table to
        > another but how do I do one table joined on two tables?
        >
        > They of course all have an ID in common.
        >
        > I already did a search on google too no help that I could find.
        >
        > I am using sql server 2005 enterprise edtion
        >
        > Thanks guys.
        >
        >
        > ------------------------------------
        >
        > Yahoo! Groups Links
        >
        >
        >
      • vigoudhaya
        ... select id from table1 where id=(select * from table2)
        Message 3 of 7 , Jun 7, 2008
        • 0 Attachment
          --- In SQLQueriesNoCode@yahoogroups.com, "Tony Trapp" <tonyt@...> wrote:
          >
          > Hey guys need some help, I know how to do inner join one table to
          > another but how do I do one table joined on two tables?
          >
          > They of course all have an ID in common.
          >
          > I already did a search on google too no help that I could find.
          >
          > I am using sql server 2005 enterprise edtion
          >
          > Thanks guys.
          >


          select id from table1 where id=(select * from table2)
        • Liviu Perniu
          It is possible to use the following sintax:   SELECT ...       FROM CandidatiRepartizati CR
          Message 4 of 7 , Jun 16, 2008
          • 0 Attachment
            It is possible to use the following sintax:
             
            SELECT ...
                  FROM CandidatiRepartizati CR
                  INNER JOIN Candidati C ON CR.CandidatID = C.CandidatID AND C.FacultateID = @iFacultateID
                  INNER JOIN OptiuniCandidati OC ON CR.CandidatID = OC.CandidatID 


            --- On Sat, 6/7/08, vigoudhaya <vigoudhaya@...> wrote:

            From: vigoudhaya <vigoudhaya@...>
            Subject: [SQLQueriesNoCode] Re: Inner join or join one table to 2 other
            To: SQLQueriesNoCode@yahoogroups.com
            Date: Saturday, June 7, 2008, 4:10 PM






            --- In SQLQueriesNoCode@ yahoogroups. com, "Tony Trapp" <tonyt@...> wrote:
            >
            > Hey guys need some help, I know how to do inner join one table to
            > another but how do I do one table joined on two tables?
            >
            > They of course all have an ID in common.
            >
            > I already did a search on google too no help that I could find.
            >
            > I am using sql server 2005 enterprise edtion
            >
            > Thanks guys.
            >

            select id from table1 where id=(select * from table2)


















            [Non-text portions of this message have been removed]
          • Liviu Perniu
            It is possible to use the following sintax:   SELECT ...       FROM table1  INNER JOIN table2 ON table1.ID =
            Message 5 of 7 , Jun 16, 2008
            • 0 Attachment
              It is possible to use the following sintax:
               
              SELECT ...
                    FROM table1  INNER JOIN table2 ON table1.ID = table2.ID INNER JOIN table3 ON table1.ID = table3.ID 
               
              It is a better idea to use a view:
               
              CREATE VIEW <view_name> AS
              SELECT... FROM table1 INNER JOIN table2 ON table1.ID=table2.ID
               
              and then
               
              SELECT ... FROM <view_name> INNER JOIN table3 ON <view_name>.ID=table3.ID
               
              good luck


              --- On Sat, 6/7/08, vigoudhaya <vigoudhaya@...> wrote:

              From: vigoudhaya <vigoudhaya@...>
              Subject: [SQLQueriesNoCode] Re: Inner join or join one table to 2 other
              To: SQLQueriesNoCode@yahoogroups.com
              Date: Saturday, June 7, 2008, 4:10 PM






              --- In SQLQueriesNoCode@ yahoogroups. com, "Tony Trapp" <tonyt@...> wrote:
              >
              > Hey guys need some help, I know how to do inner join one table to
              > another but how do I do one table joined on two tables?
              >
              > They of course all have an ID in common.
              >
              > I already did a search on google too no help that I could find.
              >
              > I am using sql server 2005 enterprise edtion
              >
              > Thanks guys.
              >

              select id from table1 where id=(select * from table2)


















              [Non-text portions of this message have been removed]
            • Damhuis Anton
              ... Please note: This email and its contents are subject to the disclaimer as displayed at the following link:
              Message 6 of 7 , Jun 18, 2008
              • 0 Attachment
                >> select id from table1 where id=(select * from table2)



                Small correction:

                Since "Select * from table2" return more then one result it will cause
                an error with the "=" in the main select statement



                It should rather be reformatted to one of the following:

                1) Select id from table1 where id=(select Max(<some column>) from
                table2)

                or

                1) Select id from table1 where id in select <some column> from
                table2)


                Regards

                Anton



                Investment Solutions Disclaimer

                Please note: This email and its contents are subject to the disclaimer as displayed at the following link:
                http://www.investmentsolutions.co.za/EmailLegalNotice.htm
                <http://www.investmentsolutions.co.za/EmailLegalNotice.htm>

                Should you have web access, send and email to legalnotice@... <mailto:legalnotice@...>
                and a copy will be sent to you.


                [Non-text portions of this message have been removed]
              • John Warner
                IN is actually rather slow in TSQL vs using a JOIN to include your list. Try it on a larger list and you will see what I mean. John Warner ... as
                Message 7 of 7 , Jun 18, 2008
                • 0 Attachment
                  IN is actually rather slow in TSQL vs using a JOIN to include your list.
                  Try it on a larger list and you will see what I mean.

                  John Warner

                  > -----Original Message-----
                  > From: SQLQueriesNoCode@yahoogroups.com
                  > [mailto:SQLQueriesNoCode@yahoogroups.com] On Behalf Of Damhuis Anton
                  > Sent: Wednesday, June 18, 2008 8:19 AM
                  > To: SQLQueriesNoCode@yahoogroups.com
                  > Subject: [SQLQueriesNoCode] Re: Inner join or join one table to 2 other
                  >
                  > >> select id from table1 where id=(select * from table2)
                  >
                  >
                  >
                  > Small correction:
                  >
                  > Since "Select * from table2" return more then one result it will cause
                  > an error with the "=" in the main select statement
                  >
                  >
                  >
                  > It should rather be reformatted to one of the following:
                  >
                  > 1) Select id from table1 where id=(select Max(<some column>) from
                  > table2)
                  >
                  > or
                  >
                  > 1) Select id from table1 where id in select <some column> from
                  > table2)
                  >
                  >
                  > Regards
                  >
                  > Anton
                  >
                  >
                  >
                  > Investment Solutions Disclaimer
                  >
                  > Please note: This email and its contents are subject to the disclaimer
                  as
                  > displayed at the following link:
                  > http://www.investmentsolutions.co.za/EmailLegalNotice.htm
                  > <http://www.investmentsolutions.co.za/EmailLegalNotice.htm>
                  >
                  > Should you have web access, send and email to legalnotice@...
                  > <mailto:legalnotice@...>
                  > and a copy will be sent to you.
                  >
                  >
                  > [Non-text portions of this message have been removed]
                  >
                  >
                  > ------------------------------------
                  >
                  > Yahoo! Groups Links
                  >
                  >
                  >
                Your message has been successfully submitted and would be delivered to recipients shortly.