We help IT Professionals succeed at work.

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

rgb192
rgb192 asked
on
310 Views
Last Modified: 2012-05-11
both tables are of same structure
itemid is primary key
sku is varchar column

select * from orderitems where orderitems123.sku!=orderitems.sku
Comment
Watch Question

Ephraim WangoyaSoftware Engineer
CERTIFIED EXPERT

Commented:

What is the question?

Author

Commented:
i want to know the rows in orderitems table
where orderitems123.sku!=orderitems.sku
CERTIFIED EXPERT
Expert of the Quarter 2010
Expert of the Year 2010

Commented:
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
Ephraim WangoyaSoftware Engineer
CERTIFIED EXPERT

Commented:


select orderitems.*
from orderitems
inner join orderitems123 on orderitems123.itemid = orderitems.itemid and  orderitems123.sku <> orderitems.sku
Imran Javed ZiaConsultant Software Engineer - .NET Architect
CERTIFIED EXPERT

Commented:
Please try this:

select * from orderitems
      Inner Join orderitems123 On orderitems123.itemid=orderitems.itemid
            And orderitems123.sku!=orderitems.sku
CERTIFIED EXPERT
Expert of the Quarter 2010
Expert of the Year 2010

Commented:
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

Author

Commented:
orderitems is newer than orderitems123 so orderitems will have more rows which means itemid (primary key)
CERTIFIED EXPERT
Expert of the Quarter 2010
Expert of the Year 2010

Commented:
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

Author

Commented:
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)
Sharath SData Engineer
CERTIFIED EXPERT

Commented:
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 SData Engineer
CERTIFIED EXPERT

Commented:
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?
CERTIFIED EXPERT
Expert of the Quarter 2010
Expert of the Year 2010
Commented:
This one is on us!
(Get your first solution completely free - no credit card required)
UNLOCK SOLUTION

Author

Commented:
thanks

Gain unlimited access to on-demand training courses with an Experts Exchange subscription.

Get Access
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Empower Your Career
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE

Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Unlock the solution to this question.
Join our community and discover your potential

Experts Exchange is the only place where you can interact directly with leading experts in the technology field. Become a member today and access the collective knowledge of thousands of technology experts.

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.