Solved

My query gives duplicates...sort of.

Posted on 2013-01-23
8
157 Views
Last Modified: 2013-03-11
I have a query that pulls information from multiple tables.  It works fine, except that one particular table might have more than one contractor for the job and I only want it to pull the single job.

So...

I have job number 55512.  I have three contractors for this job that are stored in the contractors table.  I run a query for all jobs and it returns 55512 three times because it has three contractors in the contractor table.  This particular query needs only the job and not the repeats for the contractor.  The customer is fine with it pulling only the first contractor job, but it only wants it to pull it once into the query instead of three times.

How do I do this?
0
Comment
Question by:Kevin Smith
8 Comments
 
LVL 84
Comment Utility
You'll need to give us more information regarding your table structure, as well as the SQL of the query. If possible, upload a copy of the database with any sensitive or proprietary data obfuscated.
0
 
LVL 10

Expert Comment

by:LukeChung-FMS
Comment Utility
Create a Totals query and choose Group By on that field. Only unique values will be listed.
0
 
LVL 119

Expert Comment

by:Rey Obrero
Comment Utility
<The customer is fine with it pulling only the first contractor job, but it only wants it to pull it once into the query instead of three times.>

try something like this to your query

select [job number], first([contractor])
etc/.....

group by [job number]
0
 

Author Comment

by:Kevin Smith
Comment Utility
It's making me group by everything instead of letting me group by only the Job Number field...
0
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
LVL 119

Accepted Solution

by:
Rey Obrero earned 500 total points
Comment Utility
then use the group by on the other fields except the field for contractor, use first instead of group by..


it will be easier if you upload a copy of the db
0
 

Author Comment

by:Kevin Smith
Comment Utility
The data is on a sql backend...here's the query:

SELECT DISTINCT dbo_tbl_Jobs.JobNumber, dbo_tbl_PM.PMName AS [Project Manager], dbo_tbl_Owner.OwnerName AS Ownership, dbo_tbl_Locations.State AS State, dbo_tbl_Locations.PropertyTitle AS [Property Name], dbo_tbl_Locations.UnitNumber AS [Unit Number], dbo_tbl_ProjectTracking.MProjectNumber AS [Marriott Project Number], dbo_tbl_ProjectTracking.ProjectTitle AS [Project Name], dbo_tbl_ProjectTracking.ptRYGStatus AS [RYG Status], dbo_tbl_ProjectTracking.BudgetYear AS [Budget Year], dbo_tbl_ProjectTracking.ptBudget AS [Budget Amount], dbo_tbl_ProjectTracking.BudgetChangePARAmount AS [Budget Change (PAR) Amount], dbo_tbl_ProjectTracking.PARApprovalSent AS [PAR Approval Sent to MSS], dbo_tbl_ProjectTracking.NumberOfUnits AS [Number of Units], dbo_tbl_ProjectTracking.ProjectSurveyDate AS [Project Survey Date], dbo_tbl_ProjectTracking.SurveySt, dbo_tbl_ProjectTracking.AssesmentCompleted AS [Assessment Completed/Sent], dbo_tbl_ProjectTracking.AssessmentSt, dbo_tbl_ProjectTracking.ApprovalToGoToBid AS [Approval To Go To Bid], dbo_tbl_ProjectTracking.ApprovaltoBidSt, dbo_tbl_ProjectTracking.BidPackageOut AS [Bid Package Out], dbo_tbl_ProjectTracking.BidOutSt, dbo_tbl_ProjectTracking.BidPackageDue AS [Bid Package Due], dbo_tbl_ProjectTracking.BidDueSt, dbo_tbl_ProjectTracking.BidSummaryDate AS [Bid Summary Date], dbo_tbl_ProjectTracking.BidSummarySt, dbo_tbl_ProjectTracking.ApprovalToGoToContDate AS [Approval To Go To Contract Date], dbo_tbl_ProjectTracking.ApprovalToContractSt, dbo_tbl_Contractors.Name AS Contractor, dbo_tbl_ProjectTrackingContracts.ContractIssued AS [Contract Issued to Contractor], dbo_tbl_ProjectTrackingContracts.ContractIssuedSt, dbo_tbl_ProjectTracking.MSSOrderEquipment AS [MSS Order Equipment], dbo_tbl_ProjectTracking.EqupimentOrderedSt, dbo_tbl_ProjectTracking.EstEquipmentDeliveryDate AS [Estimated Equipment Delivery Date], dbo_tbl_ProjectTracking.EquipmentDeliveredSt, dbo_tbl_ProjectTracking.ConstStart AS [Anticipated Install Start Date], dbo_tbl_ProjectTracking.ConstructionStartSt, dbo_tbl_ProjectTracking.ConstEnd AS [Estimated Completion Date], dbo_tbl_ProjectTracking.ConstructionEndSt, dbo_tbl_ProjectTracking.FinalProjectCost AS [Final Cost], dbo_tbl_ProjectTracking.Comments
FROM (((((dbo_tbl_Jobs LEFT JOIN dbo_tbl_PM ON dbo_tbl_Jobs.PM = dbo_tbl_PM.PMID) LEFT JOIN dbo_tbl_Locations ON dbo_tbl_Jobs.Location = dbo_tbl_Locations.LocationID) RIGHT JOIN dbo_tbl_ProjectTracking ON dbo_tbl_Jobs.ProjectID = dbo_tbl_ProjectTracking.ProjectID) LEFT JOIN dbo_tbl_Owner ON dbo_tbl_Locations.OwnerID = dbo_tbl_Owner.OwnerID) LEFT JOIN dbo_tbl_ProjectTrackingContracts ON dbo_tbl_ProjectTracking.PTID = dbo_tbl_ProjectTrackingContracts.ProjectTrackingID) LEFT JOIN dbo_tbl_Contractors ON dbo_tbl_ProjectTrackingContracts.ContractorID = dbo_tbl_Contractors.ContractorID
WHERE (((dbo_tbl_Jobs.CustomerID)=71) AND ((dbo_tbl_Jobs.Status)='IN PROGRESS'));
0
 

Author Comment

by:Kevin Smith
Comment Utility
any ideas?
0
 

Author Closing Comment

by:Kevin Smith
Comment Utility
I ended up firsting three different columns due to my joins, but in the end I think I got it.  thanks!
0

Featured Post

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

In the previous article, Using a Critera Form to Filter Records (http://www.experts-exchange.com/A_6069.html), the form was basically a data container storing user input, which queries and other database objects could read. The form had to remain op…
Introduction When developing Access applications, often we need to know whether an object exists.  This article presents a quick and reliable routine to determine if an object exists without that object being opened. If you wanted to inspect/ite…
Familiarize people with the process of utilizing SQL Server stored procedures from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Micr…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

772 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now