Link to home
Start Free TrialLog in
Avatar of Fred Webb
Fred WebbFlag for United States of America

asked on

Find Missing Value from Same Table

I have a Table (IV00108) that contains Item Numbers and Price Levels A, B, C, Etc I want to find Item Numbers in that table that don't have an A price level, I just can't seem to find the right formula to get it.
Avatar of Aditya Milan
Aditya Milan
Flag of India image

your question is not clear, as what exactly is to be done, but let me give it a try

select * from IV00108 where PriceLevel <> 'A'
Avatar of Fred Webb

ASKER

Adita,
No that doesn't work that just excludes that price level, I should have been clearer. An item number may have multiple price levels, for example ITEM1234 has an A, B, and C price level, your query would just eliminate the A price level and ITEM1234 would still show up in the result set. I want results where no A price level is assigned to an item number. 
select distinct ItemNumber
from IV00108 
where ItemNumber in (select ItemNumber from IV00108 where PriceLevel <> 'A')

Open in new window

Mate,
Nope... Same issue as with Adita's query it is only excluding the A price level.
It would be easier if could post some more info on your table structure, and field names, or a few example records.


select * from IV00108 where ( (PriceLevelA' = "") OR (PricelevelA = NULL))
ASKER CERTIFIED SOLUTION
Avatar of slightwv (䄆 Netminder)
slightwv (䄆 Netminder)

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
try this.

select item 
  from IV00108
 group by item
having max(case level when 'A' then 1 else 0 end) = 0

Open in new window


create table IV00108 (item varchar(20), level varchar(10))
insert into IV00108 values ('ITEM1234', 'A'), ('ITEM1234', 'B'), ('ITEM1234', 'C'), ('ITEM1235', 'B'), ('ITEM1235', 'C')
select item 
  from IV00108
 group by item
having max(case level when 'A' then 1 else 0 end) = 0

Open in new window

select itemnumber from IV00108
except
select itemnumber from IV00108 where pricelevel = 'A'
Avatar of slightwv (䄆 Netminder)
slightwv (䄆 Netminder)

Using except:  Why access the table twice when you don't have to?
I assume this is a one-time requirement and, unless there are an incredible number of rows, it should perform satisfactorily plus it is very intuitive and descriptive of its intent.. Aren't you, in essence, accessing the  table twice using a cte or subquery?
What I am trying to do is find the Item Numbers that do not have a price level of A 
Did you try the except method?
>> Aren't you, in essence, accessing the  table twice using a cte or subquery?

Depends on if the optimizer decides to materialiaze the CTE.

>>What I am trying to do is find the Item Numbers that do not have a price level of A

or try mine or Sharath's

If they don't work, post sample data and expected results.
<<
>>What I am trying to do is find the Item Numbers that do not have a price level of A

or try mine or Sharath's

If they don't work, post sample data and expected results. >>

looks like skull52 didn't even tried mine. As long as you have a working solution, let's move on.
Sharath,
I did try you solution and it did work, however slightwv's solution worked better in my case, thanks.