INSERT statement using sub-query
We can use
sub-query
for
INSERT
statement. Before inserting the record,
sub-query
gets
gender_id
based on the provided gender name
INSERT INTO students (
    first_name, 
    last_name, 
    points,
    gender_id
) 
VALUES (
    'ილია', 
    'დავითაშვილი', 
    '84',
    (SELECT id FROM genders WHERE name = 'Male')
)
by Valeri Tandilashvili
4 years ago
MySQL
INSERT
1
Pro tip: use ```triple backticks around text``` to write in code fences