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.
| Author |
Topic |
|
MaryLee
Starting Member
8 Posts |
Posted - 2011-02-08 : 11:36:39
|
| I have a table of student contains the following columns (fisrtname,lastname,grade)I want to write SQL query that retrieve a 6-column table of a pair of students who have the same grade which means ( the result table will contain student1 firstname,student1 secondname,student1 grade, student2 firstname,student2 secondname,student2 grade)the constraint is the grade will be the same. I managed to write the query but it retrieve the following records1- John Lee 50 Sarah Andrew 502- Sarah Andrew 50 John Lee 50as you can see the problem is it gives me the students who have the same grade but it gives the results twiceHow can I solve that please? |
|
|
blindman
Master Smack Fu Yak Hacker
2365 Posts |
Posted - 2011-02-08 : 11:59:07
|
| where tableA.LastName < TableB.LastName________________________________________________If it is not practically useful, then it is practically useless.________________________________________________ |
 |
|
|
webfred
Master Smack Fu Yak Hacker
8781 Posts |
Posted - 2011-02-08 : 12:02:21
|
Show your query so far please.I believe there is a join condition which means <> that could be turned to <. No, you're never too old to Yak'n'Roll if you're too young to die. |
 |
|
|
webfred
Master Smack Fu Yak Hacker
8781 Posts |
Posted - 2011-02-08 : 12:02:50
|
 No, you're never too old to Yak'n'Roll if you're too young to die. |
 |
|
|
MaryLee
Starting Member
8 Posts |
Posted - 2011-02-08 : 12:53:19
|
| thank you blindmanyou understand what I mean without even writing the SQL querythis is the professional work |
 |
|
|
webfred
Master Smack Fu Yak Hacker
8781 Posts |
Posted - 2011-02-08 : 12:59:01
|
Nevertheless you should start to ask your questions in a more professional way  No, you're never too old to Yak'n'Roll if you're too young to die. |
 |
|
|
MaryLee
Starting Member
8 Posts |
Posted - 2011-02-08 : 13:41:25
|
| hahahahahhahaha;) |
 |
|
|
blindman
Master Smack Fu Yak Hacker
2365 Posts |
Posted - 2011-02-10 : 15:00:32
|
| Technically, professional work I get paid for. This is more "pro bono" work.________________________________________________If it is not practically useful, then it is practically useless.________________________________________________ |
 |
|
|
|
|
|
|
|