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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 19, 20262026-06-19T02:17:46+00:00 2026-06-19T02:17:46+00:00

yesterday I asked this question: if in mysql insert statement and the answer works

  • 0

yesterday I asked this question: if in mysql insert statement and the answer works very well.
The problem is that I need to insert a row in my table if a value doesn’t exist.
f.e.

 If('x' NOT EXIXTS in (select campoX from table) then
 insert into table (...) values (...) etc.

How can I do? on the internet I can’t find an answer 🙁

  • 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-06-19T02:17:48+00:00Added an answer on June 19, 2026 at 2:17 am

    I assume your table is named tbl.

    INSERT INTO tbl (campoX ) 
        SELECT 'X' FROM DUAL 
        WHERE NOT EXISTS( 
                          SELECT campoX from tbl 
                          WHERE campoX ='X'
                         );
    

    DUAL is purely for the convenience of people who require that all SELECT statements should have FROM and possibly other clauses. MySQL may ignore the clauses. MySQL does not require FROM DUAL if no tables are referenced.

    As some other mentioned, you could use INSERT IGNORE statement here IF your campoX is an unigue Or primary key field.

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

Sidebar

Related Questions

This problem is related to This question I asked yesterday. Now it seems that
This question is about a similar javascript scope problem that I asked yesterday .
Yesterday in my interview I was asked this question. (At that time I was
This is linked to a question I asked yesterday. Briefly, the problem I'm having
This one is similar to a question that I asked yesterday. However my concern
I asked this question yesterday got a pretty good answer but can't figure out
I got this answer to a question i asked yesterday about how to use
This is based on a question I asked yesterday. It got very muddled, so
This question stems from this question that I asked yesterday. I've followed Theo's advice
This is a follow up to a question that was asked yesterday. I have

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.