Solved

My query gives duplicates...sort of.

Posted on 2013-01-23
8
171 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
8 Comments
 
LVL 85
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
Complete VMware vSphere® ESX(i) & Hyper-V Backup

Capture your entire system, including the host, with patented disk imaging integrated with VMware VADP / Microsoft VSS and RCT. RTOs is as low as 15 seconds with Acronis Active Restore™. You can enjoy unlimited P2V/V2V migrations from any source (even from a different hypervisor)

 

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

Three Reasons Why Backup is Strategic

Backup is strategic to your business because your data is strategic to your business. Without backup, your business will fail. This white paper explains why it is vital for you to design and immediately execute a backup strategy to protect 100 percent of your data.

Question has a verified solution.

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

Traditionally, the method to display pictures in Access forms and reports is to first download them from URLs to a folder, record the path in a table and then let the form or report pull the pictures from that folder. But why not let Windows retr…
Code that checks the QuickBooks schema table for non-updateable fields and then disables those controls on a form so users don't try to update them.
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…
What’s inside an Access Desktop Database. Will look at the basic interface, Navigation Pane (Database Container), Tables, Queries, Forms, Report, Macro’s, and VBA code.

630 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