This topic is locked

Conditional insert into another table

8/23/2024 12:13:49 PM
PHPRunner General questions
A
afa1999 author

Hi;
I have 2 tables and I would like to add a new record into another table by two conditions

  1. the level should be equal to "3"
  2. the table should have not the same two values in a record
    Here is my code, its working on mysql side but couldnt implement on phprunner

INSERT INTO table2 (Position,User,AddedBY)
SELECT Position,User,AddedBY
FROM table1
WHERE NOT EXISTS (SELECT Position, User
FROM table2
WHERE Position=Position and User=User)
AND table1.userlevel='3'

I also tried
$sql = "INSERT INTO table2 (Position, User, AddedBY) ";
$sql .= "SELECT Position, User, AddedBY FROM table1 WHERE NOT EXISTS (SELECT Position, User FROM table1 WHERE Position=".$values[Position]." and User=".$values[User].") AND userlevel=='9'";
DB::Query($sql);

I apprecate for any idea or help
Thanks in advance

C
Chris Whitehead 8/23/2024
C
Chris Whitehead 8/23/2024

Why not just wrap them in a php condition?

That might be a simpler solution.