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

  • Home
  • SEARCH
  • 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 7640303
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T08:38:11+00:00 2026-05-31T08:38:11+00:00

MySQL Tables reject_data +———–+—————–+——————+—————+ | reject_id | reject_location | reject_equipment | reject_time | +———–+—————–+——————+—————+

  • 0

MySQL Tables

reject_data

+-----------+-----------------+------------------+---------------+
| reject_id | reject_location | reject_equipment | reject_time   |
+-----------+-----------------+------------------+---------------+
| 1         | 7               | 6                | 1326795921000 |
+-----------+-----------------+------------------+---------------+
| 2         | 7               | 1                | 1326796641000 |
+-----------+-----------------+------------------+---------------+
| 3         | 7               | 6                | 1326799521000 |
+-----------+-----------------+------------------+---------------+
| 4         | 6               | 5                | 1326800781000 |
+-----------+-----------------+------------------+---------------+
| 5         | 7               | 3                | 1326802281000 |
+-----------+-----------------+------------------+---------------+
| 6         | 7               | 4                | 1326802941000 |
+-----------+-----------------+------------------+---------------+
| 7         | 7               | 1                | 1326814161000 |
+-----------+-----------------+------------------+---------------+
| 8         | 6               | 2                | 1328026700000 |
+-----------+-----------------+------------------+---------------+

equipment

+--------------+------------------+
| equipment_id | equipment_string |
+--------------+------------------+
| 1            | Microdoser       |
+--------------+------------------+
| 2            | Monoblock        |
+--------------+------------------+
| 3            | Valve Magnet     |
+--------------+------------------+
| 4            | Checkweigher     |
+--------------+------------------+
| 5            | Microleak        |
+--------------+------------------+
| 6            | Capper           |
+--------------+------------------+

locations

+-------------+-----------------+
| location_id | location_string |
+-------------+-----------------+
| 1           | Fred Line 1     |
+-------------+-----------------+
| 2           | Fred Line 2     |
+-------------+-----------------+
| 3           | Fred Line 3     |
+-------------+-----------------+
| 4           | Bob Line 1      |
+-------------+-----------------+
| 5           | Bob Line 2      |
+-------------+-----------------+
| 6           | Bob Line 3      |
+-------------+-----------------+
| 7           | Jeff Line 1     |
+-------------+-----------------+
| 8           | Jeff Line 2     |
+-------------+-----------------+
| 9           | Jeff Line 3     |
+-------------+-----------------+

emrs_data

+---------+---------------+-----------+-------------+---------------+
| emrs_id | emrs_location | emrs_code | emrs_string | emrs_time     |
+---------+---------------+-----------+-------------+---------------+
| 1       | 8             | 8744751   | String Text | 1331051832000 |
+---------+---------------+-----------+-------------+---------------+
| 2       | 3             | 8660465   | String Text | 1331051832000 |
+---------+---------------+-----------+-------------+---------------+
| 3       | 6             | 8665447   | String Text | 1331055356000 |
+---------+---------------+-----------+-------------+---------------+
| 4       | 7             | 8762177   | String Text | 1331060531000 |
+---------+---------------+-----------+-------------+---------------+
| 5       | 4             | 8547253   | String Text | 1331061898000 |
+---------+---------------+-----------+-------------+---------------+
| 6       | 9             | 8744580   | String Text | 1331062654000 |
+---------+---------------+-----------+-------------+---------------+
| 7       | 2             | 8668716   | String Text | 1331064810000 |
+---------+---------------+-----------+-------------+---------------+
| 8       | 1             | 8665436   | String Text | 1331066757000 |
+---------+---------------+-----------+-------------+---------------+
| 9       | 5             | 8761458   | String Text | 1331066847000 |
+---------+---------------+-----------+-------------+---------------+
| 10      | 8             | 8743520   | String Text | 1331068372000 |
+---------+---------------+-----------+-------------+---------------+
| 11      | 3             | 8708691   | String Text | 1331070587000 |
+---------+---------------+-----------+-------------+---------------+
| 12      | 7             | 8811149   | String Text | 1331071045000 |
+---------+---------------+-----------+-------------+---------------+

Current Queries

the following query is what i currently use, please note that I have used ‘IN’ because these are dynamic, same for the ‘BETWEEN’ values.

SELECT location_string, equipment_string, reject_time 
FROM reject_data, equipment, locations
WHERE reject_equipment = equipment_id 
    AND reject_location = location_id 
    AND reject_location IN (7) 
    AND reject_equipment IN (1,2,3,4,5,6) 
    AND reject_time BETWEEN 0 AND 1331113803000
ORDER BY reject_id DESC 
LIMIT 100

Question

What I would like to do is add two columns to the right containing emrs_code and emrs_string, please see the table below as an example. The problem I am having is trying to get the relevant emrs_code and emrs_string for each reject record, I only want to return one set of emrs results per reject and the emrs data needs to be from the nearest previous time compared to the reject_time, kinda hard to explain so here is a query that gets me the correct information for a predifined location and time:

SELECT emrs_code, emrs_string
FROM `rejectlogging`.`emrs_data`
WHERE emrs_time <= 1331113803000 AND emrs_location = 7
ORDER BY emrs_time DESC
LIMIT 1;

I am basically stuck at getting the above merged into the original query. Any help would be much appreciated. Thank you.

Desired Result

+-----------------+------------------+---------------+-----------+-------------+
| location_string | equipment_string | reject_time   | emrs_code | emrs_string |
+-----------------+------------------+---------------+-----------+-------------+
| A7              | Microleak        | 1331064910000 | 8762177   | String Text |
+-----------------+------------------+---------------+-----------+-------------+
| A3              | Checkweigher     | 1331107261000 | 8708691   | String Text |
+-----------------+------------------+---------------+-----------+-------------+
| A1              | Microdoser       | 1331107166000 | 8665436   | String Text |
+-----------------+------------------+---------------+-----------+-------------+
| A2              | Microdoser       | 1331107161000 | 8668716   | String Text |
+-----------------+------------------+---------------+-----------+-------------+
| A4              | Microleak        | 1331105836000 | 8547253   | String Text |
+-----------------+------------------+---------------+-----------+-------------+
  • 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-31T08:38:12+00:00Added an answer on May 31, 2026 at 8:38 am

    Try this:-(UPDATED)

    SELECT location_string, equipment_string, reject_time , (SELECT emrs_code
    FROM `rejectlogging`.`emrs_data`
    WHERE emrs_time <= reject_data.reject_time AND emrs_location = reject_data.reject_location
    ORDER BY emrs_time DESC
    LIMIT 1) as emrs_code,
    (SELECT emrs_string
    FROM `rejectlogging`.`emrs_data`
    WHERE emrs_time <= reject_data.reject_time AND emrs_location = reject_data.reject_location 
    ORDER BY emrs_time DESC
    LIMIT 1) as emrs_string
    FROM reject_data, equipment, locations
    WHERE reject_equipment = equipment_id 
        AND reject_location = location_id 
        AND reject_location IN (7) 
        AND reject_equipment IN (1,2,3,4,5,6) 
        AND reject_time BETWEEN 0 AND 1331113803000
    ORDER BY reject_id DESC 
    LIMIT 100
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i have two mysql tables tableA colA1 colA2 1 whatever 2 whatever 3 whatever
I have this mysql tables I want to display with jqgrid. The problem appears
I have 2 mysql tables : Question with the following columns : id, question,
I have two MySQL tables, and I want to find and replace text strings
I have 2 mysql tables 1. questions: with the following columns: id, title, answer1,
I have two mysql tables and i want to merge the results of these
I have three mysql tables items =========== id title items_in_categories ============================ id item_id category_id
I have two MySQL tables: stats (left) and messages (right) +------------+---------+ +---------+------------+-----------+----------+ | _date
Greetings, I have some mysql tables that are currently using an md5 hash as
I'm developing a spring application that uses large MySQL tables. When loading large tables,

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.