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 KudlerFineFoodsSELECT FirstName, LastName, JobTitle, EmployerInformationReport, Age FROM Employee, JobTitleWHERE 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 |
|
|
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 exampleSELECT e.FirstName,e.LastName,j.JobTitle,j.EmployerInformationReport,e.AgeFROM Employee eINNER JOIN JobTitle j ON e.EmployeeID = j.EmployeeIDWHERE e.age LIKE '%1%'JimP.S age should be a number, not a string!Everyday I learn something that somebody else already knew |
|
|
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=166616i think it should beUSE KudlerFineFoodsSELECT e.FirstName, e.LastName, jt.JobTitle, e.EmployerInformationReport, e.Age FROM Employee eINNER JOIN JobTitle jtON jt.JobID = e.JobID WHERE e.Age LIKE '%1%';GO i didnt understand relevance of '%1%' though------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
|
|
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. |
|
|
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 MVPhttp://visakhm.blogspot.com/ |
|
|
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 ShawSQL Server MVP |
|
|
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 ShawSQL Server MVP
Does not sound like a practical scenarioIt might be for training purpose i guess------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
|
|
|