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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T23:15:37+00:00 2026-05-31T23:15:37+00:00

I have two queries. The first one is.. INSERT INTO balik ( balik_date, balik_time,

  • 0

I have two queries.

The first one is..

INSERT INTO balik 
    ( balik_date, 
      balik_time, 
      balik_cardID, 
      balik_status,
      balik_type )
   select 
         current_date(), 
         '00:00:00', 
         L_CardID, 
         'BELUM BALIK', 
         L_Type 
      FROM 
         logdetail t1  
            LEFT JOIN balik t2 
               ON t1.L_CardID = t2.balik_cardID
      WHERE 
             t1.L_Type = 'IN'   
         and t1.L_Date = current_date() 
         AND t2.balik_cardID IS NULL"

and another one is..

UPDATE balik blk  
   INNER JOIN logdetail ld  
      ON blk.balik_cardID = ld.L_CardID 
     and blk.balik_date = current_date()
   SET 
      blk.balik_status = 'SUDAH BALIK', 
      blk.balik_type = 'OUT',
      blk.balik_time = ld.L_Time  
   WHERE 
          ld.L_Type = 'OUT' 
      and ld.L_Date = current_date()

My problem is that when I execute the first and second query nothing happens unless I delete all records in my table beforehand. In that case both queries are executed and work like a charm.

Why is this happening?

  • 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-31T23:15:38+00:00Added an answer on May 31, 2026 at 11:15 pm

    From what I remember, you can’t do an insert into a table that is a result of a query that may be an impact of what you are inserting… So, it MIGHT help if the select was “wrapped” inside another layer so the inner query is completely processed FIRST and thus not impacted by the inserts.

    INSERT INTO balik 
        ( balik_date, 
          balik_time, 
          balik_cardID, 
          balik_status,
          balik_type )
       select 
             PreQuery.newDate,
             PreQuery.newTime,
             PreQuery.newCardID,
             PreQuery.newStatus,
             PreQuery.newType
          from
             ( select 
                     current_date() newDate, 
                     '00:00:00'     newTime, 
                     L_CardID       newCardID, 
                     'BELUM BALIK'  newStatus, 
                     L_Type         newType
                  FROM 
                     logdetail t1  
                        LEFT JOIN balik t2 
                           ON t1.L_CardID = t2.balik_cardID
                  WHERE 
                         t1.L_Type = 'IN'   
                     and t1.L_Date = current_date() 
                     AND t2.balik_cardID IS NULL" ) PreQuery
    

    I would alter the syntax on the update to more closely match that of the SQL Syntax per documentation… list the tables comma separated, then apply join conditions in the WHERE clause

    UPDATE balik blk, logdetail ld  
       SET 
          blk.balik_status = 'SUDAH BALIK', 
          blk.balik_type = 'OUT',
          blk.balik_time = ld.L_Time  
       WHERE 
             blk.balik_cardID = ld.L_CardID 
         and blk.balik_date = current_date()
         and ld.L_Type = 'OUT' 
         and ld.L_Date = current_date()
    

    Yeah, essentially the same thing, but might be interpretation issues.

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

Sidebar

Related Questions

I have two SQL queries, where the first one is: select Activity, SUM(Amount) as
I have two queries that I would like to have merged into one. The
I have two queries and i'm using the result of the first one in
I have two queries here. First one shows listings where a cat link =
I have two queries. The first query: select in_gentime from in_time_temp where cardnumber =
I have two queries. The first returns some results and the second one returns
I have two queries, as following: SELECT SQL_CALC_FOUND_ROWS Id, Name FROM my_table WHERE Name
I have two mysql queries: $sql = SELECT * FROM content WHERE threadName LIKE
I have the following two queries: select count(*) from segmentation_cycle_recipients scr , segmentation_instance si
I have a query to select from another sub-query select. While the two queries

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.