Solved

Mysql query to compare 2 columns nd multiple rows

Posted on 2008-10-28
3
659 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Get Database Help Now w/ Support & Database Audit

Keeping your database environment tuned, optimized and high-performance is key to achieving business goals. If your database goes down, so does your business. Percona experts have a long history of helping enterprises ensure their databases are running smoothly.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

All XML, All the Time; More Fun MySQL Tidbits – Dynamically Generate XML via Stored Procedure in MySQL Extensible Markup Language (XML) and database systems, a marriage we are seeing more and more of.  So the topics of parsing and manipulating XM…
Creating and Managing Databases with phpMyAdmin in cPanel.
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

739 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