Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9266795
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T14:24:00+00:00 2026-06-18T14:24:00+00:00

I am doing a project using MySQL 5. The requirement is the following: Give

  • 0

I am doing a project using MySQL 5. The requirement is the following:

Give the user names, device types, OS version and fruit involved in picks, where users had the
same device type, were running iOS 4 or 4.1, and picked the same fruit

The relevant tables are as follows:

User: {uID: INT, name: VARCHAR(45), deviceOS: VARCHAR(45), deviceType: VARCHAR(45)}

Pick: {uID: INT, ts: TIMESTAMP, fruit: VARCHAR(45)}

(Primary keys in bold. uID in Pick is a foreign key of uID in User.)

I am doing the following query:

SELECT DISTINCT NAME1, OS1, DEV1, NAME2, OS2, DEV2, P1.fruit FROM Pick AS P1, Pick AS P2, 

(SELECT U1.uID AS User1, U1.name AS NAME1, U1.deviceOS AS OS1, U1.deviceType AS DEV1, 
        U2.uID AS User2, U2.name AS NAME2, U2.deviceOS AS OS2, U2.deviceType AS DEV2
FROM User AS U1, User AS U2 
WHERE (U1.uID != U2.uID) AND
      (U1.deviceType = U2.deviceType) AND
      (U1.deviceOS = "4" OR U1.deviceOS = "4.1") AND
      (U2.deviceOS = "4" OR U2.deviceOS = "4.1")) AS PartialResult

WHERE (P1.uID = PartialResult.User1) AND
      (P2.uID = PartialResult.User2) AND
      (P1.fruit = P2.fruit)

This returns the following result, but as you see, it is in some way "duplicated":

I have tried solving this using GROUP BY fruit but it will not return the correct result on the general case. Limit 1 also would not work on the general case. So after numerous hours trying to figure this out, I must ask:

Is there a way to prevent this kind of duplication on the general case?

Thank you!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-18T14:24:01+00:00Added an answer on June 18, 2026 at 2:24 pm

    Instead of U1.uID != U2.uID, write U1.uID > U2.uID.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm doing a school project using Drupal; and the school give us a SunOS
I'm doing a web project using jsp,mysql,ajax using netbeans and mysql. I'm having 3
I doing a WPF project using C# and LinQ. My application require user to
im doing a PHP project using codeigniter 2.1.2 , using mySql database on WAMP,
I m doing a database project using jsp and javascript and back-end using mysql.
i 'm doing a project using webview in android. i can't visit url: http://www.baidu.org
I m doing a project using eclipse plugins in jave to create an ide
I'm doing project on object detection using javacv in that I went through couple
I am doing NDK profiling for my project using android-ndk-profiler-3.1. I have made changes
Im doing a project where Alice and Bob send each other messages using the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.