Hello. I apologize for such a question, but I do not know how to formulate it differently. I'll be brief. For example, there are 2 tables. enter image description here

How can I add a line to the order table if I know only the buyer’s name and price. (So ​​I know the Name from the byer and Price tables ) I use the mysql connector / Python I tried the subquery. But it didn't work for me. And it seems to me that the subquery for such a simple task is not correct.

  • Is he invested. insert into order(ByerId,Price) select id,? from byer where Name=? . Your variables are substituted for questions (are they used in python ? used ... - Mike
  • @Mike order table name is not necessary to escape (as a keyword)? - Igor
  • Yes, it is necessary, reverse apostorphs. just here in the comments they didn’t use writing for selection - Mike

1 answer 1

Something like this:

 query="insert into `order`(ByerId,Price) select id,%s from byer where Name=%s" cursor.execute(query, (Price,Name))