Bryan Olesky
Bryan Olesky

Reputation: 579

Join Conditions in SQL

Hello I'm currently in a Intro to SQL in college. We are using Murach SQL Sever 2012 for Developers. I'm currently in Chapter 4 and I'm not understanding what a Join Condition is. I understand that is indicates how two tables should be compared, but what I can't understand is the syntax.

SELECT InvoiceNumber, Vendor name
FROM Vendors JOIN Invoices
          ON Vendors.VendorID = Invoices.VendorID;

Why is it named .VendorID?

Sorry if this is vague.

Upvotes: 0

Views: 869

Answers (3)

Anil Kumar
Anil Kumar

Reputation: 16

Implement the join condition in sql by a linq query:

 var result =(from e in employee 
              join v in vendor where e.EmployeeId equals v.EmployeeId
              select new 
              {
                    EmployeeName = e.employeeName,
                    EmployeeSalary =e.employeeSalary,
                    VendorName = v.vendorName,
                    VendorDate =v.VendorDate,        
              }).ToList();
    return (result);

Upvotes: 0

Ravi
Ravi

Reputation: 31397

Join clause combines records from two or more tables in a relational database.

Example:

If you have two table called Vendors and Invoices. Now, you are looking for common data between both table on the basis of id i.e. VendorId.

But, first of all, you need to access column of a table. So, you need to specify which table and which column. Then, it goes like mytable.thiscolumn.

Similarly, in your case you were trying to access VendorId column, which exist in both tables. So, you are explicitly telling, I need VendorId from the Vendors and Invoices.

Upvotes: 1

Alexander Staroselsky
Alexander Staroselsky

Reputation: 38767

VendorID is the name of the column in tables Vendors and Invoices. For example if you had a table named Event and a column within that table is date, you could target that property by stating Event.date

Upvotes: 1

Related Questions