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

x
?
Solved

add products.internalsku1 to a working query

Posted on 2011-03-16
3
Medium Priority
?
246 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
[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
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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say 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

I am showing a way to read/import the excel data in table using SQL server 2005... Suppose there is an Excel file "Book1" at location "C:\temp" with column "First Name" and "Last Name". Now to import this Excel data into the table, we will use…
When writing XML code a very difficult part is when we like to remove all the elements or attributes from the XML that have no data. I would like to share a set of recursive MSSQL stored procedures that I have made to remove those elements from …
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …
We’ve all felt that sense of false security before—locking down external access to a database or component and feeling like we’ve done all we need to do to secure company data. But that feeling is fleeting. Attacks these days can happen in many w…

715 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