Using JOIN in SQL Server 2012

351965 pts.
Tags:
JOIN statement
SQL Server 2012
I’m trying to create a list of all our employees by last name with their dependents by first name, and birth dates. My output columns are emp_last_name from the employee table and dep_name and dep_date_of_birth. Here is what I’ve specifically been tasked with doing:
  1. Use alias table names.
  2. Name each column appropriately
  3. Sort the result table by emp_last_name.
  4. Use the CAST statement to produce a listing that fits easily on one page.
To make matters worse, I’m teaching myself SQL Server to do this. My code so far is as follows:
SELECT emp_last_name"Employee Last Name", 
        dep_name"Dependent Name", 
       CAST(dep_date_of_birth as char(12))"Dependent Date of Birth"
from employee dependent
ORDER BY emp_last_name;

I cannot figure out how to join it because there are so many dependents with the same last name. Any thoughts?

Answer Wiki

Thanks. We'll let you know when a new response is added.
Send me notifications when members answer or reply to this question.

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy

Discuss This Question: 2  Replies

 
There was an error processing your information. Please try again later.
Thanks. We'll let you know when a new response is added.
Send me notifications when members answer or reply to this question.

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy
  • carlosdl
    Without knowing the fields in each table, we have no way to know.

    I don't think using the last name is the way to go.  There should be an emp id or similar.
    70,200 pointsBadges:
    report
  • triggermortis
    The dependents and their attributes should have their own table linked through an a primary key of emp_id to an employee table. Having the dependents within the employee table is too much (sometimes) irrelevant information to have; causes the table to become too bulky. Organization makes things much easier.
    Agreed with carlosdl:
    Emp id definitely the way to go.
    50 pointsBadges:
    report

Forgot Password

No problem! Submit your e-mail address below. We'll send you an e-mail containing your password.

Your password has been sent to:

To follow this tag...

There was an error processing your information. Please try again later.

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy

Thanks! We'll email you when relevant content is added and updated.

Following