Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

Troubleshooting
Research
Professional Opinions
Ask a Question
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE

troubleshooting Question

Requesting help with creating an SQL query with 2 tables

Avatar of earwig75
earwig75 asked on
Microsoft SQL ServerMicrosoft SQL Server 2008SQL
6 Comments1 Solution102 ViewsLast Modified:
I have 2 tables, the first table (tblCarTypes) has 2 columns, CarTypeID and CarType. The 2nd table (tblCarRecords) has some records, where one of the columns is the CarType (which is populated with the CarTypeID). I want to create a query that will output a count of records from carRecords for each CarType. Samples of the data for each table is below.

The output I would like based on the sample data below would be like this below example. Could someone assist?

This is what I want the query to output:
CarType  |  Count
suv          |  3
pickup    |  3
compact | 1


tblCarTypes:
CarType    |   CarTypeID
suv            |         1
pickup       |         2
compact    |         3


tblCarRecords:
Date     |  CarType  |  ID
3/2/15   |    1           |   1
3/3/15   |    1           |    2
3/4/15   |    1           |    3
3/4/15   |    2           |    4
3/4/15   |    2           |    5
3/4/15   |    2           |    6
3/4/15   |    3           |    7