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
 join and where

Author  Topic 

Lenjaku
Starting Member

13 Posts

Posted - 2012-07-19 : 03:35:45
I know how to join (I think I need inner join)
But I dunno how to add where condition to it (if needed)

Basically I need to get a field from table2 which is the result of a condition of field from table 1 and another field from table2.

And I need other field to simply b displayed as well.
I will give an example of the fields I need only.

Grade:
grades
grade_date
Lesson_ID <---fk

Lesson:
ID<----should this is lesson_id , it is the pk of this table
Lesson_name <---this is what I want to b displayed eventually.


So waht I want is to display grades,grade_date as is and to display
Lesson name, where Grade.Lesson_ID=Lesson_ID.

I tried this:
SELECT [Grade_date], [Grade_grade] , [Lesson_name] , [Lesson_name] FROM [grade] INNER JOIN [Lesson] ON [grade.Lesson_ID=Lesson.ID]

Didn;t work though :S

Lenjaku
Starting Member

13 Posts

Posted - 2012-07-19 : 03:36:58
Ignore the 'should' word a thte second table (lessons)
Buu why can;t I edit -.-
Go to Top of Page

Lenjaku
Starting Member

13 Posts

Posted - 2012-07-19 : 04:24:35
Ok I did get it right but the tool I was using didn;t accept this writing it needed
Lesson_ID and ID isntead of
grade.Lesson_ID and Lesson.ID

Meh :S atleast I know I was right :D
Go to Top of Page
   

- Advertisement -