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 7668865
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T15:27:57+00:00 2026-05-31T15:27:57+00:00

Okay so I am trying to get some ideas on how to go about

  • 0

Okay so I am trying to get some ideas on how to go about determining the top choices of camera I have from the table setup below. This is not a real scenario I am just trying to figure out the best way or some way to go about doing this.

So the camera table has entries id(INT) which is unique, name(VARCHAR), reviewRank(INT), price(INT), and failRate(INT). Here is an example of the TABLE setup and inserts code:

CREATE TABLE CAMERA(
id INTEGER,
name VARCHAR(30),
reviewRank INT,
price INT,
failRate INT,
PRIMARY KEY(id))ENGINE=INNODB;

INSERT INTO CAMERA VALUES(1,'Camera 1',5,100,1);
INSERT INTO CAMERA VALUES(2,'Camera 2',4,300,7);
INSERT INTO CAMERA VALUES(3,'Camera 3',1,10,99);
INSERT INTO CAMERA VALUES(4,'Camera 4',1,10,6);

Criteria is that a higher reviewRank is better, a lower price is better, and a lower failRate is better. And if multiple cameras share the best value for one of the columns then we choose the one with the best values in the other two columns or if multiple cameras have the same values in multiple columns such as CAMERA(3,’Camera 3′,1,10,99) and CAMERA(4,’Camera 4′,1,10,6) do then the last column determines the outcome.

Basically any camera with the best value in any of the three columns automatically becomes a candidate for the list of top cameras to choose from. But if multiple cameras have the best value for the same column then we need to determine which is the best of these by looking at the values of the other columns.

So using the database state above the query would return cameras (1,’Camera 1′,5,100,1) and (4,’Camera 4′,1,10,6) since camera id 1 has the highest reviewRank and lowest failRate and camera id 4 and camera id 3 tie for having the lowest price but camera id 4 has a lower failRate than camera id 3.

So basically I am trying to figure a way to go about finding the top choices where there are multiple column comparisons using MySQL preferably using a single query if possible.

My initial thoughts were something like this

SELECT DISTINCT C.* 
FROM CAMERA C
WHERE C.reviewRank>=ALL(SELECT reviewRank FROM CAMERA)
OR    C.price<=ALL(SELECT price FROM CAMERA)
OR    C.failRate<=ALL(SELECT failRate FROM CAMERA);

However this is obviously wrong since it does not cover all of the possible permutations.
And after doing quite a bit of searching for a way to go about this I still have no idea how to go about this.

  • 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-05-31T15:27:58+00:00Added an answer on May 31, 2026 at 3:27 pm

    I believe that the ORDER BY clause accomplishes what you’re looking for:

    SELECT topC.Id, topC.Name, topC.ReviewRank, topC.Price, topC.FailRate
    FROM Camera topC JOIN (
        (SELECT c.ReviewRank, c.Price, c.FailRate
        FROM Camera c
        ORDER BY 
            c.ReviewRank DESC,
            c.Price,
            c.FailRate
        LIMIT 1)
        UNION 
        (SELECT c.ReviewRank, c.Price, c.FailRate
        FROM Camera c
        ORDER BY 
            c.Price,
            c.FailRate,
            c.ReviewRank DESC
        LIMIT 1)
        UNION 
        (SELECT c.ReviewRank, c.Price, c.FailRate
        FROM Camera c
        ORDER BY 
            c.FailRate,
            c.Price,
            c.ReviewRank DESC
        LIMIT 1)
    ) values 
        ON values.ReviewRank = topC.ReviewRank
        AND values.Price = topC.price
        AND values.FailRate = topC.FailRate
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have some strange issue when trying to apply a conversion from HSI to
okay, I'm still trying to get my head around some of the caching stuff
Okay, I'm trying to get ActionBarSherlock working, so I imported the library by: Creating
Okay, so I am trying to wrap my head around how to get stuff
Okay I been trying to work this out but unable too. I have a
okay i have been trying to understand this for hours i am learning VB
Okay so I've been trying to position these 4 divs for about 6 hours
Okay here is what I'm trying to do: I have a model object that
Okay... I'm getting kind of desperate trying to get this code to work with
Okay so I'm just trying to write some simple code that updates a record

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.