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
 Too many instances

Author  Topic 

nhuot1
Starting Member

1 Post

Posted - 2012-03-07 : 10:09:43
I'm relatively new to SQL report writing, and I need help.
I'm trying to pull all students who have a specific attribute. The problem is that each student has many attributes and even though I specify student_attribute = 'FF07' I get numerous entries (all identical) for each student.
How do I only retrieve a single entry for each student?
I use this code:

select t.id, t.last_name, t.first_name, b.student_attribute,
. . .

from t, b
where t.pidm = b.pidm
and b.student_attribute = 'FF07'

I tried using select distinct t.id, but I get the same results.
Any thoughts?

X002548
Not Just a Number

15586 Posts

Posted - 2012-03-07 : 10:17:48
you're gonna have to give us more than that

Read the hint link in my sig


Brett

8-)

Hint: Want your questions answered fast? Follow the direction in this link
http://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspx


Want to help yourself?

http://msdn.microsoft.com/en-us/library/ms130214.aspx

http://weblogs.sqlteam.com/brettk/

http://brettkaiser.blogspot.com/


Go to Top of Page

DonAtWork
Master Smack Fu Yak Hacker

2167 Posts

Posted - 2012-03-07 : 10:18:14
try this:

SELECT DISTINCT
t.id, t.last_name, t.first_name, b.student_attribute
FROM
t
INNER JOIN
b
ON
t.pidm = b.pidm
AND
b.student_attribute = 'FF07'


EDIT: lose your mind reading hat Brett?

http://weblogs.sqlteam.com/jeffs/archive/2008/05/13/question-needed-not-answer.aspx
How to ask: http://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspx

For ultra basic questions, follow these links.
http://www.sql-tutorial.net/
http://www.firstsql.com/tutor.htm
http://www.w3schools.com/sql/default.asp
Go to Top of Page

webfred
Master Smack Fu Yak Hacker

8781 Posts

Posted - 2012-03-07 : 10:21:07
just a shot: duplicate students in table "t" with different ids

garbage in / garbage out


No, you're never too old to Yak'n'Roll if you're too young to die.
Go to Top of Page
   

- Advertisement -