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
 help in writing sql query

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 records

1- John Lee 50 Sarah Andrew 50
2- Sarah Andrew 50 John Lee 50

as you can see the problem is it gives me the students who have the same grade but it gives the results twice

How 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.
________________________________________________
Go to Top of Page

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.
Go to Top of Page

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.
Go to Top of Page

MaryLee
Starting Member

8 Posts

Posted - 2011-02-08 : 12:53:19
thank you blindman
you understand what I mean without even writing the SQL query
this is the professional work

Go to Top of Page

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.
Go to Top of Page

MaryLee
Starting Member

8 Posts

Posted - 2011-02-08 : 13:41:25
hahahahahhahaha
;)
Go to Top of Page

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.
________________________________________________
Go to Top of Page
   

- Advertisement -