Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Joins

Author  Topic 

kprofgold
Starting Member

15 Posts

Posted - 2011-10-15 : 17:57:28
Im trying to figure out how to minimize data in this join query. I am getting way to much. I know I'm missing something.

USE KudlerFineFoods
SELECT FirstName, LastName, JobTitle, EmployerInformationReport, Age
FROM Employee, JobTitle
WHERE Age LIKE '%1%';
GO

kprofgold
Starting Member

15 Posts

Posted - 2011-10-15 : 18:42:55
Ok i read a bit more of my book and noticed I need the JOIN statement but am very confused on how to use it with = and the other elements needed. Mu book is very confusing
Go to Top of Page

jimf
Master Smack Fu Yak Hacker

2875 Posts

Posted - 2011-10-15 : 19:25:11
There should be at least one field that is common to both tables, and that's what you want to use in your join. For example
SELECT e.FirstName,e.LastName,j.JobTitle,j.EmployerInformationReport,e.Age
FROM Employee e
INNER JOIN JobTitle j ON e.EmployeeID = j.EmployeeID
WHERE e.age LIKE '%1%'

Jim

P.S age should be a number, not a string!

Everyday I learn something that somebody else already knew
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2011-10-16 : 00:13:52
as per

http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=166616

i think it should be


USE KudlerFineFoods
SELECT e.FirstName, e.LastName, jt.JobTitle, e.EmployerInformationReport, e.Age
FROM Employee e
INNER JOIN JobTitle jt
ON jt.JobID = e.JobID
WHERE e.Age LIKE '%1%';
GO


i didnt understand relevance of '%1%' though


------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page

kprofgold
Starting Member

15 Posts

Posted - 2011-10-16 : 01:38:50
The syllabus asked for an age restriction so I used 1 to find all employees with a 1 in their age. Out of 15 employees the query found 2 employees with a 1 in their age. Thank you all for your replies they really did help.
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2011-10-16 : 02:34:01
quote:
Originally posted by kprofgold

The syllabus asked for an age restriction so I used 1 to find all employees with a 1 in their age. Out of 15 employees the query found 2 employees with a 1 in their age. Thank you all for your replies they really did help.


welcome

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page

GilaMonster
Master Smack Fu Yak Hacker

4507 Posts

Posted - 2011-10-16 : 02:52:02
quote:
Originally posted by kprofgold

The syllabus asked for an age restriction so I used 1 to find all employees with a 1 in their age.


Odd restriction. So any of these ages are acceptable?

1, 10-19, 21, 31, 41, 51, 61, 71, 81, 91, 100, 101?

--
Gail Shaw
SQL Server MVP
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2011-10-16 : 02:53:52
quote:
Originally posted by GilaMonster

quote:
Originally posted by kprofgold

The syllabus asked for an age restriction so I used 1 to find all employees with a 1 in their age.


Odd restriction. So any of these ages are acceptable?

1, 10-19, 21, 31, 41, 51, 61, 71, 81, 91, 100, 101?

--
Gail Shaw
SQL Server MVP


Does not sound like a practical scenario
It might be for training purpose i guess

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page
   

- Advertisement -