sql - MySQL Insert from 2 source tables to one destination table -


i having issues inserting id fields 2 tables single record in third table.

mysql> describe ing_titles; +----------+------------------+------+-----+---------+----------------+ | field    | type             | null | key | default |          | +----------+------------------+------+-----+---------+----------------+ | id_title | int(10) unsigned | no   | pri | null    | auto_increment | | title    | varchar(64)      | no   | uni | null    |                | +----------+------------------+------+-----+---------+----------------+ 2 rows in set (0.22 sec)  mysql> describe ing_categories; +-------------+------------------+------+-----+---------+----------------+ | field       | type             | null | key | default |          | +-------------+------------------+------+-----+---------+----------------+ | id_category | int(10) unsigned | no   | pri | null    | auto_increment | | category    | varchar(64)      | no   | uni | null    |                | +-------------+------------------+------+-----+---------+----------------+ 2 rows in set (0.02 sec)  mysql> describe ing_title_categories; +-------------------+------------------+------+-----+---------+----------------+ | field             | type             | null | key | default |          | +-------------------+------------------+------+-----+---------+----------------+ | id_title_category | int(10) unsigned | no   | pri | null    | auto_increment | | id_title          | int(10) unsigned | no   | mul | null    |                | | id_category       | int(10) unsigned | no   | mul | null    |                | +-------------------+------------------+------+-----+---------+----------------+ 3 rows in set (0.04 sec)    

let's data tables is:

mysql> select * ing_titles; +----------+-------------------+ | id_title | title             | +----------+-------------------+ |        3 | chicken           | |        2 | corn              | |        1 | fettucini alfredo | +----------+-------------------+ 3 rows in set (0.00 sec)  mysql> select * ing_categories; +-------------+----------+ | id_category | category | +-------------+----------+ |           1 | dinner   | |           3 | meat     | |           2 | veggie   | +-------------+----------+ 3 rows in set (0.00 sec)   

i want insert ing_title_categories record "corn, veggie" or id_title = 2 , id_category = 2.

here's tried:

insert ing_title_categories (id_title, id_category) select ing_titles.id_title, ing_categories.id_category ing_title_categories     left join ing_titles on ing_title_categories.id_title=ing_titles.id_title     left join ing_categories on ing_title_categories.id_category=ing_categories.id_category (ing_titles.id_title=2) , (ing_categories.id_category = 2); 

there no data inserted table ing_title_categories, , here reply mysql:

query ok, 0 rows affected (0.00 sec) records: 0  duplicates: 0  warnings: 0 

what correct syntax inserting ing_titles.id_title , ing_categories.id_category table ing_titles_categories?

please, no php or python examples. use sql can copy , paste mysql prompt. adding c++ program, not php, javascript or python.

edit 1: ing_title_categories.id_title , ing_title_categories.id_category foreign keys other tables.

insert     ing_title_categories (id_title, id_category) select     ing_titles.id_title, ing_categories.id_category     ing_titles, ing_categories     ing_titles.id_title = ing_categories.id_category ,     ing_titles.id_title = 2 , ing_categories.id_category = 2; 

sql fiddle demo


Comments

Popular posts from this blog

angularjs - ADAL JS Angular- WebAPI add a new role claim to the token -

php - CakePHP HttpSockets send array of paramms -

node.js - Using Node without global install -