Solved

My query gives duplicates...sort of.

Posted on 2013-01-23
8
168 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
ID: 38810623
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:Luke Chung
ID: 38810671
Create a Totals query and choose Group By on that field. Only unique values will be listed.
0
 
LVL 120

Expert Comment

by:Rey Obrero (Capricorn1)
ID: 38810718
<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
NFR key for Veeam Backup for Microsoft Office 365

Veeam is happy to provide a free NFR license (for 1 year, up to 10 users). This license allows for the non‑production use of Veeam Backup for Microsoft Office 365 in your home lab without any feature limitations.

 

Author Comment

by:Kevin Smith
ID: 38810974
It's making me group by everything instead of letting me group by only the Job Number field...
0
 
LVL 120

Accepted Solution

by:
Rey Obrero (Capricorn1) earned 500 total points
ID: 38811009
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
ID: 38811603
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
ID: 38877574
any ideas?
0
 

Author Closing Comment

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

Featured Post

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction The Visual Basic for Applications (VBA) language is at the heart of every application that you write. It is your key to taking Access beyond the world of wizards into a world where anything is possible. This article introduces you to…
Preparing an email is something we should all take special care with – especially when the email is for somebody you may not know very well. The pressures of everyday working life stacked with a hectic office environment can make this a real challen…
In Microsoft Access, learn the trick to repeating sub-report headings at the top of each page. The problem with sub-reports and headings: Add a dummy group to the sub report using the expression =1: Set the “Repeat Section” property of the dummy…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

821 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