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

x
?
Solved

add products.internalsku1 to a working query

Posted on 2011-03-16
3
Medium Priority
?
249 Views
Last Modified: 2012-05-11

select * from products where productid IN (
select distinct pi.productid from ebaytitles et
inner join packageitems pi on pi.packageid=et.packageid
union
select distinct et.packageid from ebaytitles et
inner join products p on p.productid=et.packageid
)
order by productid desc

works but when I add products.internalsku1 (varchar) to last line i get error



Msg 156, Level 15, State 1, Line 9
Incorrect syntax near the keyword 'where'.


select * from products where productid IN (
select distinct pi.productid from ebaytitles et
inner join packageitems pi on pi.packageid=et.packageid
union
select distinct et.packageid from ebaytitles et
inner join products p on p.productid=et.packageid
)
where internalsku1 is not null order by productid desc






0
Comment
Question by:rgb192
3 Comments
 
LVL 32

Assisted Solution

by:Ephraim Wangoya
Ephraim Wangoya earned 600 total points
ID: 35152084
Use and


elect * from products where productid IN ( 
select distinct pi.pro
ductid from ebaytitles et
inner join packageitems pi on pi.packageid=et.packageid
union
select distinct et.packageid from ebaytitles et
inner join products p on p.productid=et.packageid
) 
and internalsku1 is not null 
order by productid desc

Open in new window

0
 
LVL 41

Accepted Solution

by:
Sharath earned 1400 total points
ID: 35152183
Replacing the WHERE with AND for filter on internalsku1 will solve the problem as ewangoya mentioned.You have UNION and DISTINCT in the sub-query. UNION will take care of distinct values so you can eliminate DISTINCT.
SELECT * 
    FROM products 
   WHERE productid IN (SELECT pi.productid 
                         FROM ebaytitles et 
                              INNER JOIN packageitems pi 
                                ON pi.packageid = et.packageid 
                       UNION 
                       SELECT et.packageid 
                         FROM ebaytitles et 
                              INNER JOIN products p 
                                ON p.productid = et.packageid) 
         AND internalsku1 IS NOT NULL 
ORDER BY productid DESC

Open in new window

0
 

Author Closing Comment

by:rgb192
ID: 35152458
thanks
0

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

Question has a verified solution.

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

If you having speed problem in loading SQL Server Management Studio, try to uncheck these options in your internet browser (IE -> Internet Options / Advanced / Security):    . Check for publisher's certificate revocation    . Check for server ce…
There are some very powerful Dynamic Management Views (DMV's) introduced with SQL 2005. The two in particular that we are going to discuss are sys.dm_db_index_usage_stats and sys.dm_db_index_operational_stats.   Recently, I was involved in a di…
Is your data getting by on basic protection measures? In today’s climate of debilitating malware and ransomware—like WannaCry—that may not be enough. You need to establish more than basics, like a recovery plan that protects both data and endpoints.…
Despite its rising prevalence in the business world, "the cloud" is still misunderstood. Some companies still believe common misconceptions about lack of security in cloud solutions and many misuses of cloud storage options still occur every day. …

824 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