Link to home
Start Free TrialLog in
Avatar of rgb192
rgb192Flag 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
Avatar of Ephraim Wangoya
Ephraim Wangoya
Flag of United States of America image


What is the question?
Avatar of rgb192

ASKER

i want to know the rows in orderitems table
where orderitems123.sku!=orderitems.sku
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


select orderitems.*
from orderitems
inner join orderitems123 on orderitems123.itemid = orderitems.itemid and  orderitems123.sku <> orderitems.sku
Please try this:

select * from orderitems
      Inner Join orderitems123 On orderitems123.itemid=orderitems.itemid
            And orderitems123.sku!=orderitems.sku
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
Avatar of rgb192

ASKER

orderitems is newer than orderitems123 so orderitems will have more rows which means itemid (primary key)
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
Avatar of 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)
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?
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
Avatar of cyberkiwi
cyberkiwi
Flag of New Zealand image

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
Avatar of rgb192

ASKER

thanks