?
Solved

My query gives duplicates...sort of.

Posted on 2013-01-23
8
Medium Priority
?
172 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
Simplifying Server Workload Migrations

This use case outlines the migration challenges that organizations face and how the Acronis AnyData Engine supports physical-to-physical (P2P), physical-to-virtual (P2V), virtual to physical (V2P), and cross-virtual (V2V) migration scenarios to address these challenges.

 

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 2000 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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Access custom database properties are useful for storing miscellaneous bits of information in a format that persists through database closing and reopening.  This article shows how to create and use them.
This article describes a method of delivering Word templates for use in merging Access data to Word documents, that requires no computer knowledge on the part of the recipient -- the templates are saved in table fields, and are extracted and install…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…

719 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