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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T15:28:19+00:00 2026-05-13T15:28:19+00:00

I have a database where I would like to construct a result that match

  • 0

I have a database where I would like to construct a result that match my indata.

Explanation of examples:
“Indata” is a row with criteria for the filter in step #1, see below.
“Results after filter #1” is the rows left after step #1
“Results after filter #2” is the rows left after step #2
“Print for indata 1” is the end result, presenting the contect of field OutData after the second filtering, along with the combined content of field “Warn”

Step #1. Filter the Outdata table to only keep records matching Indata. Star * is matching anything. Each row must match the indata row. See examples.

Step #1b. Indata Depl is not matched directly but checked to be in the range OutData
Depl-DeplOffMin>Indata Depl

Step #2. Filter Outdata table again, to only keep unique rows for each Pos, select the row with lowest Mismatch when duplicates exist. See examples.

Step #3. Create all possible combinations of the Outdata Field, with unique Pos. Like LOOP: OutData for first Pos=10 + OutData for first Pos=20 + OutData for first Pos=30 + OutData for first Pos=30, see “Print” lines in the examples.

Step #4. Sort the output combinations ie the “Print” lines, to have lowest mismatch on the top. See examples.

Would you try to do this as one big SQL query, or build temporary tables etc mixing it with PHP doing more of the work?

(The real database is perhaps 1000rows and 30 fields in MySQL. The Indata is sent to the server via Ajax and the server code in PHP generates the Print data and sends it back.)

"Outdata" table, example:

Pos   OutData     Warn  Mismatch    Producer    Depl        DeplOffMax        DeplOffMin  Axis        Connection
10    S                 0           S           *           *                 *                       *           *
20    24                0           S           24          *                 *           *           *
20    24          +-5   5           S           24          5                 -5          *           *
20    24          +-10  10          S           24          10                -10         *           *
20    48                0           S           48          *                 *           *           *
30    AA                0           S           *           *                 *           A           *
30    AB                0           S           *           *                 *           B           *
30    AC                0           S           *           *                 *           C           *
30    AA          B-AA  5           S           *           *                 *           B
40    C1                0           S           *           *                 *           *           C1
40    C1                1           S           *           *                 *           B           *
40    C1                2           S           24          10                -10         *           *
40    C2                0           S           *           *                 *           *           C2





Example 1:
Indat 1:                           S           24                                        A           C2

Result for indata 1 after filter #1:
10    S                 0           S           *           *                 *                       *           *
20    24                0           S           24          *                 *           *           *
20    24          +-5   5           S           24          5                 -5          *           *
20    24          +-10  10          S           24          10                -10         *           *
30    AA                0           S           *           *                 *           A           *
40    C1                2           S           24          10                -10         *           *
40    C2                0           S           *           *                 *           *           C2

Result for indata 1 after filter #2:
10    S                 0           S           *           *                 *                       *           *
20    24                0           S           24          *                 *           *           *
30    AA                0           S           *           *                 *           A           *
40    C1                2           S           24          10                -10         *           *
40    C2                0           S           *           *                 *           *           C2

Print for indata 1:
Mismatch 0:       S 24 AA C2  Warning -
Mismatch 2:       S 24 AA C1  Warning -



Example 2:
Indata 2:                           S           33                                        B           C2

Result for indata 2 after filter #1:
10    S                 0           S           *           *                 *                       *           *
20    24          +-10  10          S           24          10                -10         *           *
30    AB                0           S           *           *                 *           B           *
30    AA          B-AA  5           S           *           *                 *           B
40    C1                1           S           *           *                 *           B           *
40    C1                2           S           24          10                -10         *           *
40    C2                0           S           *           *                 *           *           C2

Result for indata 2 after filter #2:
10    S                 0           S           *           *                 *                       *           *
20    24          +-10  10          S           24          10                -10         *           *
30    AB                0           S           *           *                 *           B           *
30    AA          B-AA  5           S           *           *                 *           B
40    C1                1           S           *           *                 *           B           *
40    C2                0           S           *           *                 *           *           C2

Print for indata 2:
Mismatch 10:      S 24 AB C2  Warning: +-10
Mismatch 11:      S 24 AB C1  Warning: +-10
Mismatch 15:      S 24 AA C2  Warning: +-10 B-AA
Mismatch 16:      S 24 AA C1  Warning: +-10 B-AA





Example 3:
Indata 3:                           S           28                                        B           C1

Result for indata 3 after filter #1:
10    S                 0           S           *           *                 *                 *           *
20    24          +-5   5           S           24          5                 -5          *           *
20    24          +-10  10          S           24          10                -10         *           *
30    AB                0           S           *           *                 *           B           *
30    AA          B-AA  5           S           *           *                 *           B
40    C1                0           S           *           *                 *           *           C1
40    C1                1           S           *           *                 *           B           *
40    C1                2           S           24          10                -10         *           *

Result for indata 3 after filter #2:
10    S                 0           S           *           *                 *                 *           *
20    24          +-5   5           S           24          5                 -5          *           *
30    AB                0           S           *           *                 *           B           *
30    AA          B-AA  5           S           *           *                 *           B
40    C1                0           S           *           *                 *           *           C1

Print for indata 3:
Mismatch 5:       S 24 AB C1  Warning: +-5
Mismatch 10:      S 24 AA C1  Warning: +-5 B-AA
  • 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-13T15:28:20+00:00Added an answer on May 13, 2026 at 3:28 pm

    I have no idea what step 3 means, but all the other steps can be done in SQL, also, they probably should be done in SQL where its a lot more efficient.

    I assume from your tags that you’re using a MySQL database (it would have been helpful to know).

    My initial thots would be somethnig along the lines of:

     SELECT outdata.Pos,
         outdata.OutData,
         outdata.Warn,
         MIN(outdata.Mismatch),    
         outdata.Producer,
         outdata.Depl,
         outdata.DeplOffMax,        
         outdata.DeplOffMin,
         outdata.Axis
         outdata.Connection
     FROM outdata, indata
     WHERE
       (//some nasty type juggling here
         outdata.depl='*'
         OR outdata.deploffmin='*'
         OR indata.depl='*'
         OR (
            outdata.depl<>'*'
            AND outdata.deploffmin<>'*'
            AND indata.depl<>'*'
            AND outdata.depl-outdata.deploffmin>indata.depl
         )
       )  
     AND ( outdata.outdata=indata.outdata
       OR outdata.outdata='*'
       OR indata.outdata='*' )
     AND ( outdata.connection=indata.connection
       OR outdata.connection = '*'
       OR indata.connection='*' )
     AND (outdata.axis=indata.axis
       OR outdata.axis='*' 
       OR indata.axis='*' )
     ....repeat for all the fields you want to match       
     GROUP BY outdata.Pos,
         outdata.OutData,
         outdata.Warn,    
         outdata.Producer,
         outdata.Depl,
         outdata.DeplOffMax,        
         outdata.DeplOffMin,
         outdata.Axis
         outdata.Connection
     ORDER BY 4 ASC;
    

    Simples.

    C.

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

Sidebar

Ask A Question

Stats

  • Questions 366k
  • Answers 366k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer The SQL Azure team recommends using SQL Server 2008 R2… May 14, 2026 at 4:35 pm
  • Editorial Team
    Editorial Team added an answer You can try right-clicking by holding Control and clicking the… May 14, 2026 at 4:35 pm
  • Editorial Team
    Editorial Team added an answer Paperclip doesn't allow to pass function as size limit parameter.… May 14, 2026 at 4:35 pm

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.