Love Fuel?    Donate

FuelPHP Forums

Ask your question about FuelPHP in the appropriate forum, or help others by answering their questions.
Insert where not exists
  • Hello all, I am trying to only insert a database record only if there is no existing record with two of the same values.
    I can accomplish this with two queries and an if statement but I would prefer to combine them into one statement.
    I can accomplish that with the following sql:
    INSERT INTO progresses (user_id, object_type, object_id)
    SELECT 1, 0, 2
    FROM DUAL WHERE NOT EXISTS (
     SELECT id FROM progresses WHERE user_id = 1 AND object_id = 2
    )
    
    Is it possible to do this using query builder?
  • Use DB::query().
  • Thats what I thought. Thanks for confirming.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

In this Discussion