Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

My query gives duplicates...sort of.

Posted on 2013-01-23
8
Medium Priority
?
173 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 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
Nothing ever in the clear!

This technical paper will help you implement VMware’s VM encryption as well as implement Veeam encryption which together will achieve the nothing ever in the clear goal. If a bad guy steals VMs, backups or traffic they get nothing.

 

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: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

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

Instead of error trapping or hard-coding for non-updateable fields when using QODBC, let VBA automatically disable them when forms open. This way, users can view but not change the data. Part 1 explained how to use schema tables to do this. Part 2 h…
Explore the ways to Unlock VBA Project Password Excel 2010 & 2013 documents. Go through the article and perform the steps carefully to remove VBA Excel .xls file.
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…
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…

971 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