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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T20:23:12+00:00 2026-05-28T20:23:12+00:00

I am used to doing this in sql server IF (SELECT COUNT(*) FROM table

  • 0

I am used to doing this in sql server

IF (SELECT COUNT(*) FROM table WHERE column1=@value1) = 0
INSERT INTO table(column1, column2, column3) VALUES(@value1, @value2, @value3)

But I can’t really get it to work in MySql. Please help 🙂

—————- EDIT ——————

There shouldn’t be a lot of fuss or magic involved in this, I would assume.

If an e-mail does not exist in a table then insert several values into that table.

That’s it. Preferbly a one liner, to embed in programming code.

  • 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-28T20:23:13+00:00Added an answer on May 28, 2026 at 8:23 pm

    another way to do this is using the INSERT IGNORE statement. Assuming column1 should only hold unique values, you can add a UNIQUE KEY constraint on the field (if its not your primary key already):

    ALTER TABLE table ADD UNIQUE KEY column1 (column1)
    

    you can then write your query as such:

    INSERT IGNORE INTO table(column1, column2, column3) VALUES(@value1, @value2, @value3)
    

    or if you want to automatically update the other fields, use ON DUPLICATE KEY UPDATE:

    INSERT INTO table(column1, column2, column3) VALUES(@value1, @value2, @value3) 
    ON DUPLICATE KEY UPDATE column2 = @value2,  column3 = @value3
    

    letting the database handle it automatically using unique key has several advantages:

    • better performance and scalability through usage of indexes as opposed to full table scans
    • failsafe – you can not add two rows with same unique identifier accidentally with a wrong query
    • better readability of your queries

    NOTE: a unique key may also span multiple rows. stupid example: combination of “ip” and “port” may be combined as the unique identifier “connection”.

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

Sidebar

Related Questions

we are migrating over to oracle from sql server side. on sqlserver we used
I found this nice example of doing paging in SQL Server, however, I need
I come from PHP background and am used to doing var_dump , echo and
I have a table that I wish to select a subset of columns from
Okay so I'm writing a SQL Server 2008 Stored Procedure (maintenance script). In doing
Sorry for the long question but this contains all the SQL I've used to
TSQL (as used in MS SQL Server 2000 and 2005) allows multiple JOIN clauses,
I have a sql server table of licence keys/serial numbers. Table structure is something
I'm reading a file from a SQL server and writing it to disk temporarily
I'm working on returning a recordset from SQL Server 2008 to do some pagination.

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.