Mysql
 sql >> Database >  >> RDS >> Mysql

Inserisci SQL nella selezione da più campi

Potresti usare un self-join:

INSERT INTO jobs
  (customer_id, client_id)
SELECT customer.id, client.id
FROM   users customer
  JOIN users client ON customer.username = ? AND client.username = ?

Oppure puoi usare le sottoquery:

INSERT INTO jobs
  (customer_id, client_id)
VALUES (
  (SELECT id FROM users WHERE username = ?),
  (SELECT id FROM users WHERE username = ?)
)