?
Solved

Select query from 2 tables

Posted on 2014-08-11
4
Medium Priority
?
387 Views
Last Modified: 2014-08-12
I have two tables. One table is called Employees and one is called Teams.

In the Employee table I have the following columns (Name, StartDate, Position, TeamID)
In the Teams table I have the following columns (URL, Active, TeamID)

I want to select Name, StartDate, and Position from the Employee table
as well as
URL, and Active from the Teams table
Where the ID is the same

For example...
Employee record: Mike Smith | 1/1/1980 | Comptroller | 55
Teams record: www.google.com | Yes | 55

would display this in the result:

Mike Smith 1/1/1980 Comptroller www.google.com Yes

How do I do this?
0
Comment
Question by:Mike Miller
4 Comments
 
LVL 15

Accepted Solution

by:
Vikas Garg earned 2000 total points
ID: 40254928
Hi,

You have to use Join

select Name, StartDate, Position, URL, Active  from Employee 
INNER JOIN Teams ON Employee .TeamID = Teams.TeamID

Open in new window

0
 
LVL 35

Expert Comment

by:David Todd
ID: 40254983
0
 
LVL 49

Expert Comment

by:PortletPaul
ID: 40255052
another SQL tutorial site: http://sqlzoo.net/wiki/Main_Page
0
 
LVL 31

Expert Comment

by:hnasr
ID: 40255089
Agree with Vikas Garg's comment as a direct answer. Other comments help in the learning process.

If you need more info on INNER JOIN to join more tables see this article:
INNER JOIN a Number of Tables
0

Featured Post

Get quick recovery of individual SharePoint items

Free tool – Veeam Explorer for Microsoft SharePoint, enables fast, easy restores of SharePoint sites, documents, libraries and lists — all with no agents to manage and no additional licenses to buy.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In the first part of this tutorial we will cover the prerequisites for installing SQL Server vNext on Linux.
When trying to connect from SSMS v17.x to a SQL Server Integration Services 2016 instance or previous version, you get the error “Connecting to the Integration Services service on the computer failed with the following error: 'The specified service …
This video shows how to Export data from an Oracle database using the Datapump Export Utility.  The corresponding Datapump Import utility is also discussed and demonstrated.
Viewers will learn how the fundamental information of how to create a table.
Suggested Courses

864 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question