Wrox Programmer Forums
|
SQL Server 2000 General discussion of Microsoft SQL Server -- for topics that don't fit in one of the more specific SQL Server forums. version 2000 only. There's a new forum for SQL Server 2005.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the SQL Server 2000 section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old October 31st, 2006, 03:12 PM
Authorized User
 
Join Date: Oct 2006
Posts: 14
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via AIM to DeMoNN
Default Select Distinct Question

HI

im working for a school system and im having trouble with my current assignment

i have 4 tables that are used
here are the tables, fields are blue Key is bold

1) Adjuncts: FName, LName, SocSec, AdjNum
i.e.: bob | Dole | 988-23-1234 | 1
      bill | clinton | 123-45-4321 | 2
2) Adjunct_Titles: DeptName, TitleName, PartFullTime, AdjNum, ID
i.e.: English | Assis. Prof. Step1 | PT | 1 | 1
      English | Assis. Prof. Step2 | PT | 1 | 2
      English | Assist. CLT Step1 | FT | 1 | 3
      Biology | Assist. CLT Step1 | FT | 2 | 4
3) Titles: TitleName, TitleNum, CurrentPayrate, TitleID
i.e.: Assis. Prof. Step1 | 1 | $35 | 1
      Assis. Prof. Step2 | 1 | $38 | 2
      Assis. CLT Step2 | 2 | $18 | 3
4) Dept : DeptName, DeptNum
i.e.: English | 111
      Bio | 112

anyway..
i need to make a report on all employees in a spacific dept to send to each dept seperately

just replace adjunct with employee to understand

my query is

SELECT DISTINCTROW Adjuncts.LName, Adjuncts.FName, Adjuncts.SocSec, Adj_Titles.DeptName, Adj_Titles.Title, Titles.CurrentPayRate, Adj_Titles.FullPartTime, Adj_Titles.AdjNum
FROM Adjuncts INNER JOIN (Titles INNER JOIN (Depts INNER JOIN Adj_Titles ON Depts.DeptName = Adj_Titles.DeptName) ON Titles.Title = Adj_Titles.Title) ON Adjuncts.AdjNum = Adj_Titles.AdjNum
WHERE (((Depts.DeptNum)=[Enter Dept Number:]))
ORDER BY Adjuncts.LName;


the problem:
i want to return distinct results PLUS non destinct results
problem2: i only want to show the later steps for title is more than one step exists on record


here is the query i have to get it

SELECT DISTINCT Adj_Titles.AdjNum, Adj_Titles.DeptName, Titles.TitleNum
FROM Titles INNER JOIN Adj_Titles ON Titles.Title = Adj_Titles.Title
GROUP BY Adj_Titles.AdjNum, Adj_Titles.DeptName, Titles.TitleNum;


it returns ADJNUM, DEPT, TITLENUM
ADJNUM says who the employee is
DEPT says which dept.
TITLENUM makes it specific to differnt titles minus the duplicates of titles on differnt steps


now i wanna take this table that has X amount of records
and add data to it from other tables

so that i still have X records

instead i keep getting Y records because it adds extra


thanks for listening

I was here but now I'm gone.
I leave this messege to be carried on.
Whoever knew me, knew me well.
Whoever didn't, go to hell.
__________________
I was here but now I\'m gone.
I leave this messege to be carried on.
Whoever knew me, knew me well.
Whoever didn\'t, go to hell.
 
Old October 31st, 2006, 03:29 PM
Authorized User
 
Join Date: Oct 2006
Posts: 14
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via AIM to DeMoNN
Default

i found someone asking the same question except i guess he had alternative motives and changed his mind so his post didnt answer my question :



 When one applies Select Distinct to field X in a query only those records which have a unique field X are displayed.

But what if you want all fields in the record, but still based on field X being unique?
<s>
Also is there a way to get .FieldCount similar to .RecordCount property?

Thanks - Kirk</s>


 Try something like...

SELECT DISTINCT FieldX, FieldA, FieldB

Mike
EchoVue.com
 As soon as another field is added 'fieldX'loses it's distinctness.
This may well be no solution.




unfortunately... I need that solution
thanks again

I was here but now I'm gone.
I leave this messege to be carried on.
Whoever knew me, knew me well.
Whoever didn't, go to hell.
 
Old October 31st, 2006, 10:37 PM
Friend of Wrox
 
Join Date: Oct 2006
Posts: 475
Thanks: 0
Thanked 9 Times in 9 Posts
Default

 
Quote:
quote:Try something like...
Quote:

SELECT DISTINCT FieldX, FieldA, FieldB
Ok... WHICH FieldA and WHICH FieldB do you want if there is more than one?

--Jeff Moden
 
Old November 1st, 2006, 11:01 AM
Authorized User
 
Join Date: Oct 2006
Posts: 14
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via AIM to DeMoNN
Default

point was that, that didnt work


I was here but now I'm gone.
I leave this messege to be carried on.
Whoever knew me, knew me well.
Whoever didn't, go to hell.
 
Old November 1st, 2006, 02:52 PM
Authorized User
 
Join Date: Oct 2006
Posts: 14
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via AIM to DeMoNN
Default

solution in thread http://p2p.wrox.com/topic.asp?TOPIC_ID=51686

I was here but now I'm gone.
I leave this messege to be carried on.
Whoever knew me, knew me well.
Whoever didn't, go to hell.





Similar Threads
Thread Thread Starter Forum Replies Last Post
Select Distinct Question DeMoNN Access 4 November 1st, 2006 11:15 AM
Select Distinct Question acdsky SQL Server 2000 6 October 31st, 2006 05:16 PM
Select Distinct? [email protected] SQL Language 5 November 5th, 2005 09:58 AM
Distinct SELECT DISTINCT question... EndEffect Classic ASP Databases 4 August 18th, 2005 08:53 AM
select distinct bmains ADO.NET 0 April 8th, 2004 02:50 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.