Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win


I want the productid where packageitemid is the min

Posted on 2011-02-25
Medium Priority
Last Modified: 2012-05-11
combine these two queries
$packageitemid=SELECT min(packageitems.packageitemid) FROM packageitems LEFT JOIN products ON packageitems.productid = products.productid
 select productid from packageitems where packageitemid=$packageitemid

I want the productid where packageitemid is the min

Question by:rgb192
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
LVL 23

Accepted Solution

Rajkumar Gs earned 1332 total points
ID: 34980874
Check whether this is working ?
SELECT top 1 productid, min(packageitemid) as minpackageitemid
FROM packageitems 
group by productid
order by minpackageitemid

Open in new window

LVL 23

Assisted Solution

by:Rajkumar Gs
Rajkumar Gs earned 1332 total points
ID: 34980882
select productid from packageitems where packageitemid=
(SELECT min(packageitems.packageitemid) FROM packageitems LEFT JOIN products ON packageitems.productid = products.productid)

Open in new window

LVL 50

Assisted Solution

Lowfatspread earned 668 total points
ID: 34981619
Select productid
  from packageitems as pi
 Where packageitemid =
    (select min(packageitemid)
        from packageitems)
  order by 1

since its a left outer join products  you don't need to have it

Author Closing Comment

ID: 34981916

Featured Post

Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

Question has a verified solution.

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

Introduction This article will provide a solution for an error that might occur installing a new SQL 2005 64-bit cluster. This article will assume that you are fully prepared to complete the installation and describes the error as it occurred durin…
Use this article to create a batch file to backup a Microsoft SQL Server database to a Windows folder.  The folder can be on the local hard drive or on a network share.  This batch file will query the SQL server to get the current date & time and wi…
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…
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…

609 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