Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Problem with Select Distinct Query

Posted on 2008-10-21
2
Medium Priority
?
208 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 750 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

New benefit for Premium Members - Upgrade now!

Ready to get started with anonymous questions today? It's easy! Learn more.

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…
Confronted with some SQL you don't know can be a daunting task. It can be even more daunting if that SQL carries some of the old secret codes used in the Ye Olde query syntax, such as: (+)     as used in Oracle;     *=     =*    as used in Sybase …
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…
Suggested Courses

722 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