Avatar of rgb192
rgb192
Flag for United States of America asked on

select * from orderitems where orderitems123.sku!=orderitems.sku

both tables are of same structure
itemid is primary key
sku is varchar column

select * from orderitems where orderitems123.sku!=orderitems.sku
Microsoft SQL Server 2005

Avatar of undefined
Last Comment
rgb192

8/22/2022 - Mon
Ephraim Wangoya


What is the question?
rgb192

ASKER
i want to know the rows in orderitems table
where orderitems123.sku!=orderitems.sku
cyberkiwi

All records in orderitems where the sku does not exist in the other table orderitems123

select a.*
from orderitems a
left join orderitems123 b on a.sku=b.sku
where b.sku is null
This is the best money I have ever spent. I cannot not tell you how many times these folks have saved my bacon. I learn so much from the contributors.
rwheeler23
Ephraim Wangoya



select orderitems.*
from orderitems
inner join orderitems123 on orderitems123.itemid = orderitems.itemid and  orderitems123.sku <> orderitems.sku
Imran Javed Zia

Please try this:

select * from orderitems
      Inner Join orderitems123 On orderitems123.itemid=orderitems.itemid
            And orderitems123.sku!=orderitems.sku
cyberkiwi

Or if they both have itemid, and you want to match by itemid but where the sku for the itemid-itemid match is not the same:

select a.*
from orderitems a
join orderitems123 b on a.itemid=b.itemid
where a.sku!=b.sku
⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.
rgb192

ASKER
orderitems is newer than orderitems123 so orderitems will have more rows which means itemid (primary key)
cyberkiwi

You can swap sku for itemid in the query I gave earlier

i.e. new rows in orderitems

select a.*
from orderitems a
left join orderitems123 b on a.itemid=b.itemid
where b.itemid is null
rgb192

ASKER
how to combine

select a.*
from orderitems a
join orderitems123 b on a.itemid=b.itemid
where a.sku!=b.sku


select a.*
from orderitems a
left join orderitems123 b on a.itemid=b.itemid
where b.itemid is null


want rows where sku are different (different skus, or one row doesnt exist)
I started with Experts Exchange in 2004 and it's been a mainstay of my professional computing life since. It helped me launch a career as a programmer / Oracle data analyst
William Peck
Sharath S

If orderitems has skus as 1,2,3,4 and orderitems123 has skus as 3.4,5,6. Now based on this sample, which skus are you expecting in the result set?
Sharath S

type in previous post. Its supposed to be comma between 3 and 4.

If orderitems has skus as 1,2,3,4 and orderitems123 has skus as 3,4,5,6. Now based on this sample, which skus are you expecting in the result set?
ASKER CERTIFIED SOLUTION
cyberkiwi

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
rgb192

ASKER
thanks
⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.