Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 664
  • Last Modified:

Mysql query to compare 2 columns nd multiple rows

I have one table with 3 values:
tablex
sku_id       weight1        weight2
1234           1                   2
1234           1.4                2

I need to identify any sku_id in column sku_id that has more than one entry. After that I need identify every SKU that has identical values in weight2 but has different values in weight1.

IN the example above 1234 has multiple entries in the table and weight2 is equal for both entries. However weight1 does not equal the other weight1 for the other entry. It is not required that weight1 = weight2 just we identify any weight1 that is not equal to the other weight1 but both weight2 entries are equal.
0
azit2000
Asked:
azit2000
  • 3
1 Solution
 
Roger BaklundCommented:
First part is easy, the below code will show all sku_id with more than 1 entry
select sku_id,count(*) as entries
from tablex
group by sku_id
having entries > 1

Open in new window

0
 
Roger BaklundCommented:
The next query is a bit more complicated. You could try with a self join:
select t1.sku_id,t1.weight2,
  t1.weight1 as t1_weight1,
  t2.weight1 as t2_weight1
from tablex as t1,tablex as t2
where 
  t1.sku_id = t2.sku_id and 
  t1.weight2 = t2.weight2 and
  t1.weight1 <> t2.weight1 

Open in new window

0
 
Roger BaklundCommented:
Did my answer not resolve your issue?

http://www.experts-exchange.com/help.jsp#hi403
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now