Fred Webb
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.
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.
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')
ASKER
Mate,
Nope... Same issue as with Adita's query it is only excluding the A price level.
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
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
try this.
select item
from IV00108
group by item
having max(case level when 'A' then 1 else 0 end) = 0
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
select itemnumber from IV00108
except
select itemnumber from IV00108 where pricelevel = 'A'
except
select itemnumber from IV00108 where pricelevel = 'A'
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?
ASKER
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.
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.
>>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.
ASKER
Sharath,
I did try you solution and it did work, however slightwv's solution worked better in my case, thanks.
I did try you solution and it did work, however slightwv's solution worked better in my case, thanks.
select * from IV00108 where PriceLevel <> 'A'