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

The Archive Base Latest Questions

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

I have some data from two tables: Table prod_schedule Line Model Lot_no Quantity Lot_Quantity

  • 0

I have some data from two tables:

Table prod_schedule
Line      Model      Lot_no      Quantity    Lot_Quantity
FA 01     KD-R330JD  060A        240         1000
FA 01     KD-R330JD  060A        260         1000
FA 02     KD-R330JD  060A        400         1000
FA 02     KD-R330JD  060A        100         1000

Table inspection_report
Line      Model      Lot_no      Merchandise
FA 01     KD-R330JD  060A        200        
FA 01     KD-R330JD  060A        300         
FA 02     KD-R330JD  060A        500         

I want to show data like:

Line      Model      Lot_no      Merchandise   Quantity
FA 01     KD-R330JD  060A        500           500
FA 02     KD-R330JD  060A        500           500

And I try some query like:

SELECT A.Line, TRIM(A.Model) AS Model,A.Lot_no,B.Quantity,A.Merchandise
FROM inspection_report A
LEFT JOIN prod_schedule B
ON A.Line= B.Line_Name AND CONCAT('%',B.Model_Code,'%') LIKE CONCAT('%',A.Model,'%') 
                        AND A.Lot_no=B.Lot_No_
WHERE A.Model LIKE '%330%' AND A.Lot_no LIKE '%060%'
GROUP BY A.Line,A.Model,A.Lot_no,Merchandise

But I get result like :

Line    Model     Lot_no    Merchandise Quantity 
FA 01   KD-R330JD   060A    200          240
FA 02   KD-R330JD   060A    300          240
  • 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-27T15:33:45+00:00Added an answer on May 27, 2026 at 3:33 pm

    [ Post Overhaul ]

    With the most recent update of the question, here’s the code that would generate the desired output:

    -- VERSION 01
    SELECT t1.Line, t1.Model, t1.Lot_no, t1.Merchandise, t2.Quantity
    FROM
    (
        SELECT 
              A.Line, TRIM(A.Model) AS Model, A.Lot_no
            , SUM(A.Merchandise) AS Merchandise
        FROM lk_inspection_report AS A
        GROUP BY A.Line, TRIM(A.Model), A.Lot_no
    ) t1
    INNER JOIN
    (
        SELECT 
              B.Line, TRIM(B.Model) AS Model, B.Lot_no
            , SUM(B.Quantity) AS Quantity
        FROM lk_prod_schedule AS B
        GROUP BY B.Line, TRIM(B.Model), B.Lot_no
    ) t2
    ON 
            t1.Line = t2.Line 
        AND t1.Model = t2.Model 
        AND t1.Lot_no = t2.Lot_no
    WHERE 
            t1.Model LIKE '%330%' 
        AND t1.Lot_no LIKE '%060%'
    

    And this is..

    -- VERSION 02
    SELECT t1.Line, t1.Model, t1.Lot_no, t1.Merchandise, t2.Quantity
    FROM
    (
        SELECT 
              A.Line, TRIM(A.Model) AS Model, A.Lot_no
            , SUM(A.Merchandise) AS Merchandise
        FROM lk_inspection_report AS A
        WHERE t1.Model LIKE '%330%' AND t1.Lot_no LIKE '%060%'
        GROUP BY A.Line, TRIM(A.Model), A.Lot_no
    ) t1
    INNER JOIN
    (
        SELECT 
              B.Line, TRIM(B.Model) AS Model, B.Lot_no
            , SUM(B.Quantity) AS Quantity
        FROM lk_prod_schedule AS B
        WHERE B.Model LIKE '%330%' AND B.Lot_no LIKE '%060%'
        GROUP BY B.Line, TRIM(B.Model), B.Lot_no
    ) t2
    ON 
            t1.Line = t2.Line 
        AND t1.Model = t2.Model 
        AND t1.Lot_no = t2.Lot_no
    

    I aggregated data from each table and then joined them after the grouping. Version 2 places the WHERE clause in both sub queries; please test which is faster for you.

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

Sidebar

Related Questions

I have two tables from two different databases. For example: Table: Articles1 - Database:
i'm trying to migrate some data from two tables in an OLD database, to
I want to join two tables together and have ONLY the data in Table
High level I have two tables that need to have some of the data
I want to fetch a data from two tables even if the second table
I have some data, yes, data. This data came from a MySQL query and
I have some data that comes regularily as a dump from a data souce
We have recently moved some data from an SQL Database instance to another one
I have some existing code that retrieves data from a database using ADO.NET that
We have some C# code that reads data from a text file using a

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.