Solved

Problem with Select Distinct Query

Posted on 2008-10-21
2
207 Views
Last Modified: 2011-09-20
Hi all,

As below as attached is my query to retrieve data from my database.

There is same multiple shortagepn from my database but i just wanted them to appear as 1 on my display table. the thing now is sometimes there is no data found or even duplicated shortagepn appear on my table. is there something wrong with my query or is there anyway i can use other than using the distinct method.

Thanks
Dim qryselect As String = "Select distinct projects.shortagepn, projects.pono,projects.description,projects.uploadby, projects.duedate, projects.poqty,projects.actualbyrname_cus,projects.programtype,projects.shortqty,projects.assembly_mo,outstandingpo.supplier_name,projects.sides,projects.familyid,projects.mono, companyname.companyname FROM (loading.projects INNER JOIN loading.outstandingpo ON outstandingpo.item_number = projects.shortagepn) INNER JOIN loading.companyname ON projects.familyid = companyname.familyid WHERE projects.familyid='" & familyid & "' AND projects.assembly_mo='" & assemblyno & "' AND projects.mono='" & mono & "' AND projects.shortagepn <>''"

Open in new window

0
Comment
Question by:bosscat
[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
2 Comments
 
LVL 5

Accepted Solution

by:
jfmador earned 250 total points
ID: 22772988
The Select Distinct will show you distinct row. Since you have multiple column they will be distinct if you look to all column

If you want only a list of projects.shortagepn you should only specify this column in your query

Select distinct projects.shortagepn FROM (loading.projects INNER JOIN loading.outstandingpo ON outstandingpo.item_number = projects.shortagepn) INNER JOIN loading.companyname ON projects.familyid = companyname.familyid WHERE projects.familyid='" & familyid & "' AND projects.assembly_mo='" & assemblyno & "' AND projects.mono='" & mono & "' AND projects.shortagepn <>''"
 
or use grouping using MAX, MIN, SUM, AVG, etc in your select statement.

Like :
Select distinct projects.shortagepn, Max(projects.duedate) as MaxDueDate, sum(projects.poqty) as sumpoqty
FROM (loading.projects INNER JOIN loading.outstandingpo ON outstandingpo.item_number = projects.shortagepn) INNER JOIN loading.companyname ON projects.familyid = companyname.familyid WHERE projects.familyid='" & familyid & "' AND projects.assembly_mo='" & assemblyno & "' AND projects.mono='" & mono & "' AND projects.shortagepn <>''"
GROUP BY projects.shortagepn
 
0
 
LVL 1

Author Comment

by:bosscat
ID: 22774355
thanks jfmador for the help!
0

Featured Post

Give Your Engineering Team a Productivity Boost

Learn why container technology is so powerful and how it can provide your team with productivity gains and other benefits.

Question has a verified solution.

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

As they say in love and is true in SQL: you can sum some Data some of the time, but you can't always aggregate all Data all the time! Introduction: By the end of this Article it is my intention to bring the meaning and value of the above quote to…
In part one, we reviewed the prerequisites required for installing SQL Server vNext. In this part we will explore how to install Microsoft's SQL Server on Ubuntu 16.04.
There's a multitude of different network monitoring solutions out there, and you're probably wondering what makes NetCrunch so special. It's completely agentless, but does let you create an agent, if you desire. It offers powerful scalability …
Michael from AdRem Software outlines event notifications and Automatic Corrective Actions in network monitoring. Automatic Corrective Actions are scripts, which can automatically run upon discovery of a certain undesirable condition in your network.…

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