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
 Real-life problem to solve with SQL

Author  Topic 

wcodydecker
Starting Member

3 Posts

Posted - 2010-01-13 : 16:59:53
Hello,

I have a database table called "STUDENT" with the following fields:

SchoolCode (int)
StudentID (int)
StudentLastName (string)
StudentEntryDate (datetime)
StudentWithdrawalDate (datetime)
SchoolYear (datetime)

The goal is display all students that are enrolled in more than school at the same time for a given school year. To accomplish this, I need to use the StudentEntryDate and StudentWithdrawalDate. I'm not sure how to compare records with other records within the same table. Might you have any suggestions? I'm using SQL Server 2005. Many thanks in advance.

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2010-01-13 : 17:13:45
I prefer problems that teachers makeup for their students.

Show us what you have tried at least.

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog

"Let's begin with the premise that everything you've done up until this point is wrong."
Go to Top of Page

wcodydecker
Starting Member

3 Posts

Posted - 2010-01-13 : 18:19:27
I'm not looking for the final solution so much as ideas on where to begin. (I'm not a student; I work in education). I'm familiar with basic SQL statements and have used Oracle several years ago but I'm not familiar with this type of a nested SQL query (I'm presuming it'll be nested SQL statements). Preliminary idea is to physically duplicate the table with the same data so I can query off of two instead of one.

Thanks!

Go to Top of Page

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2010-01-13 : 18:22:52
You should post sample data along with the expected output so that your problem is more clear.

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog

"Let's begin with the premise that everything you've done up until this point is wrong."
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2010-01-14 : 00:19:09
Sounds like what you're asking for is self join. see below

http://msdn.microsoft.com/en-us/library/ms177490.aspx
Go to Top of Page
   

- Advertisement -