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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T01:34:35+00:00 2026-05-23T01:34:35+00:00

I have a problem inserting a row in a MySQL table when the table

  • 0

I have a problem inserting a row in a MySQL table when the table is completely empty.
I use this query :

INSERT IGNORE INTO test (id, amount) 
SELECT 6, 50 FROM test WHERE NOT EXISTS 
(SELECT 1 FROM test WHERE amount >= 50 AND id = 6) LIMIT 1

It works fine when there is at least one entry in the table, whatever the data in the columns are. It doesn’t work if the table is completely empty.

Basically, I want to insert a row if a row with the same ID and an amount equals or higher doesn’t exists.

I tried with a COUNT also, still the same problem. Is there another way of doing this?

  • 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-23T01:34:36+00:00Added an answer on May 23, 2026 at 1:34 am

    I think the only thing wrong with this is on line two, remove FROM test.. You can’t select 6, 50 from test.. 6 and 50 are not columns in test, and test has no records. Try it like this:

    INSERT IGNORE INTO test (id, amount) 
    SELECT * from (select 6, 50) as a 
    WHERE NOT EXISTS (SELECT 1 FROM test 
                      WHERE amount >= 50 AND id = 6)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Table in MySQL have 1 problem column: creation_date . During inserting a new row
i have a problem in inserting the listbox value into mysql database in vb
i have a problem in inserting the listbox value into mysql database in vb
I have a problem in php code inserting values into database (I use PHPMyAdmin).
i have a problem in inserting some data into a table. I have done
I have a problem with inserting data into SQLite database using QSqlTableModel. The table
I'm having a strange problem in that I have php inserting text into a
I have problem with generating and inserting xml in existing document. <table:table table:template-name=default> <table:table-column
I have this query, which should insert an amount if an amount equals or
I am inserting say 500 rows using INSERT IGNORE, if the row already exists

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.