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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T06:05:41+00:00 2026-06-14T06:05:41+00:00

Here is description of my scenario: myTable : ID name width1 width2 parameter1 parameter2

  • 0

Here is description of my scenario:

myTable:

ID name width1 width2 parameter1 parameter2 code
1  AAA  0      10     500        750        10001
2  AAA  0      10     750        1250       10002 
3  AAA  0      10     900        1400       10003
4  AAA  0      10     1150       1650       10004
.................................................
.................................................
.................................................

Lets say that I’m working with some “subjects” that have their own properties. Based on subject properties and some calculations with that same properties I should take “code” from this table.

So, this one subject that I’m currently working with has name: AAA, width: 5, and with my calculations i get parameter: 1000. After I have all of necessary attributes I can compare them with rows in myTable. For bigger picture I’ll select all from this table but my goal is to get code. Here is query for that:

SELECT * FROM myTable WHERE name="AAA" AND 5>=width1 AND 5<=width2 AND 1000>=parameter1 AND 1000<=parameter2

After this I get these two rows:

ID name width1 width2 parameter1 parameter2 code
2  AAA  0      10     750        1250       10002 
3  AAA  0      10     900        1400       10003

Just to mention, here could be one row. But, if I get two rows I need to do following. My whole concentration is on these parameters in a way that I’m comparing spread between my parameter and parameter2 in first row and spread between my parameter and parameter1 in second row.

parameter -> parameter2
1250 - 1000 = 250
&
parameter1 -> parameter
1000 - 900 = 100

So, if spread1:250 > spread2:100 take code2:00002 else take code3:00003.

My question is, how to compare values from different rows and columns? As you can see I have two rows and values from different column. What I need is a way to select these specific values for comparison.

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-14T06:05:43+00:00Added an answer on June 14, 2026 at 6:05 am

    It seems to be solved by Greatest from Least, so at first we get the least value and order this descent.

    SELECT 
      code
    FROM 
      myTable 
    WHERE 
      name="AAA" 
    AND 
      5 >= width1 
    AND 
      5 <= width2 
    AND 
      1000 >= parameter1 
    AND 
      1000 <= parameter2
    ORDER BY 
      Least( parameter2-1000, 1000-parameter1 ) desc
    LIMIT 1;
    

    SQL Fiddle

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

Sidebar

Related Questions

Here is my scenario (Tables): Orders ====================== Id (int) description (varchar) Products ====================== Id
Would appreciate any kind of help here. A brief description about scenario - There
Here is a description of the scenario and I would appreciate also any comments
![enter image description here][1]On my two demo and screenshot, you can understand that so
I'm using the savetxt function (description here ) to save a matrix to a
Is there any body can confirm the description here is true? My experience is
Gradient with transparency![enter image description here][1] I wanted to apply transparent multicolor gradient at
How to find below comment block(s) with javascript/jquery regex: /* some description here */
Here is a description in MSDN of the indexed view:As modifications are made to
I have a homework problem here I've been working on; here is the description:

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.