Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Mysql query to compare 2 columns nd multiple rows

Posted on 2008-10-28
3
Medium Priority
?
662 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 750 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

Will your db performance match your db growth?

In Percona’s white paper “Performance at Scale: Keeping Your Database on Its Toes,” we take a high-level approach to what you need to think about when planning for database scalability.

Question has a verified solution.

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

Introduction Since I wrote the original article about Handling Date and Time in PHP and MySQL several years ago, it seemed like now was a good time to update it for object-oriented PHP.  This article does that, replacing as much as possible the pr…
By, Vadim Tkachenko. In this article we’ll look at ClickHouse on its one year anniversary.
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…
Suggested Courses

670 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