Description of the problem: there are 2 tables tabel_home and table_users and they are connected 1 to many and when adding a new entry to the table tabel_home you have to check tabel_home there is an entry in the tabel_users , if there is to receive its id if there is no add and receive id .
Now I use php to solve this:
function GetUserId($user_name, $mysqli) { $sql_select = "SELECT id FROM tabel_users WHERE user = $user_name;"; if($result_id = $mysqli->query($sql_select)) { if($result_id != Null) { return $result_id->fetch_assoc()['id']; } else { $sql_insert = "INSERT INTO tabel_users (user) VALUE ($user_name);"; $mysqli->query($sql_insert); return $mysqli->insert_id; } } else { return False; } } But it is interesting to have a faster and more convenient way of getting or adding a record and getting its id and preferably using SQL .
INSERT IGNOREand then make aSELECTsomething like that what is written in @Akina in UPD - Alexey Shimansky