Solved

Mysql query to compare 2 columns nd multiple rows

Posted on 2008-10-28
3
655 Views
Last Modified: 2012-05-05
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
Comment
Question by:azit2000
  • 3
3 Comments
 
LVL 39

Expert Comment

by:Roger Baklund
ID: 22826390
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
 
LVL 39

Accepted Solution

by:
Roger Baklund earned 250 total points
ID: 22826471
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
 
LVL 39

Expert Comment

by:Roger Baklund
ID: 23087051
Did my answer not resolve your issue?

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

Featured Post

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

Creating and Managing Databases with phpMyAdmin in cPanel.
Load balancing is the method of dividing the total amount of work performed by one computer between two or more computers. Its aim is to get more work done in the same amount of time, ensuring that all the users get served faster.
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…

746 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

7 Experts available now in Live!

Get 1:1 Help Now