Results 1 to 3 of 3

Thread: If Exists?

  1. #1
    Join Date
    Oct 2004
    Posts
    13

    Unanswered: If Exists?

    What (if any) is the equivalent of SQL Servers IF EXISTS command in MySQL?

    SQL Server example:
    IF EXISTS (SELECT * FROM MYTABLE WHERE COLUMN=2)
    (
    INSERT INTO OTHERTABLE (COL) VALUES ('c')
    )

  2. #2
    Join Date
    Feb 2004
    Location
    In front of the computer
    Posts
    15,579
    Provided Answers: 54
    I don't know of any equivalent, but that doesn't mean that none exists.

    -PatP

  3. #3
    Join Date
    Jan 2006
    Posts
    20
    I just found an example myself! This example does an insert if a condition is met. Replace everything in brackets [] with known values.


    Code:
    IF EXISTS (select [col] from [table] where [col] = [value]) THEN
    insert into [table] ([col]) values ([value]);
    END IF;

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •