| Author |
Topic |
|
zaidqis
Yak Posting Veteran
63 Posts |
Posted - 2006-06-08 : 16:01:30
|
| hi alli have questionwhat is joins , i know that joins is used to get data from multie table ,,i found explanation about joins but i cant understand it because i didnt understand the tables structureso ..can you explain how to use joins in this casei have two tablefirst :: student table it containsID : the id of the studentName : the name of the studentsecond :: marks table it containsID :the id of the studentmark : student marki want to make sql steatment get the name of the student from student tableand the mark of the student from marks table and use parameter to determine the student from his IDthank you |
|
|
tkizer
Almighty SQL Goddess
38200 Posts |
Posted - 2006-06-08 : 16:05:47
|
| An obvious homework question, but I'm bored. So I'll answer it even though we shouldn't answer homework questions.DECLARE @StudentIDSELECT s.NameFROM Student sINNER JOIN Mark mON s.ID = m.IDWHERE s.ID = @StudentIDRead your class materials for more information joins. If you still don't understand it, ask your teacher to help you with the concept.Tara Kizeraka tduggan |
 |
|
|
zaidqis
Yak Posting Veteran
63 Posts |
Posted - 2006-06-08 : 16:26:01
|
| thank youbut really it is not homework , and i dont have teacheri am 17 years old from north of iraqand i am learnning english now ,, and trying to study vb 2005 , sql server 2005thank you |
 |
|
|
zaidqis
Yak Posting Veteran
63 Posts |
Posted - 2006-06-08 : 16:28:03
|
i have a question quote: FROM Student sINNER JOIN Mark m
why you put s after student and m after mark ??thank you |
 |
|
|
tkizer
Almighty SQL Goddess
38200 Posts |
Posted - 2006-06-08 : 16:33:19
|
| Those are aliases. It makes it easier to read and shortens your code. After aliasing an object, you can now say AliasName.ColumnName instead of TableName.ColumnName. One to three letter aliases are what I prefer. Developers who use XML will typically give the alias a more descriptive name.Tara Kizeraka tduggan |
 |
|
|
zaidqis
Yak Posting Veteran
63 Posts |
Posted - 2006-06-08 : 16:42:02
|
| thank you very much |
 |
|
|
sprite007
Starting Member
3 Posts |
Posted - 2006-06-08 : 18:45:20
|
I understand the select statements in the code, but I am not sure what the following does:DECLARE @StudentID......WHERE s.ID = @StudentIDcan't the query work with just the following:SELECT s.Name, markFROM Student sINNER JOIN Mark mON s.ID = m.IDPlease forgive me as I am just a beginner and I feel like I have a decent understanding of writing the queries but when the queries are transformed into scripts, I am lost and clueless.Dan |
 |
|
|
tkizer
Almighty SQL Goddess
38200 Posts |
Posted - 2006-06-08 : 18:47:05
|
| The query will work if you don't use the variable. But it will return the data for all students found in both tables. The question was how to do it for one student using a variable.I actually missed a step in the code. It should be:DECLARE @StudentID intSET @StudentID = SomeIDGoesHereSELECT s.NameFROM Student sINNER JOIN Mark mON s.ID = m.IDWHERE s.ID = @StudentIDTara Kizeraka tduggan |
 |
|
|
sprite007
Starting Member
3 Posts |
Posted - 2006-06-08 : 18:57:51
|
Thank you so much. Do you know where I can go to for more information on basic sql programming or scripting? I am in no way a programmer. Thank you for quick response.Dan |
 |
|
|
tkizer
Almighty SQL Goddess
38200 Posts |
Posted - 2006-06-08 : 19:01:14
|
| I don't have a beginner's book to recommend. I'd search amazon.com and check out the reviews for the beginner T-SQL books. For advanced books, I'd recommend Ken Henderson's books:http://www.sqlteam.com/store.aspTara Kizeraka tduggan |
 |
|
|
|