How to Insert Data Into Join Tables? |
I can select and join, but I can't insert with these below tables in the same time. How to insert data into joined tables?
- tbl_category(cate_id, name, description) - tbl_brand(brand_id, brand_name) - tbl_product(product_id, product_name, cate_id, brand_id)
I don't think MySQL allows you to do a joined insert, so you'd just do three inserts inside a transaction.
05-26-2016, 01:00 AM
(This post was last modified: 05-26-2016, 01:41 AM by Phally Seng. Edit Reason: Add specific question )
Yes, I think so. But I find this idea. How to do it in Codeigniter?
Code: INSERT INTO table3 ( name, age, sex, city, id, number, nationality) And I also find trigger. Which one is better to avoid lost data?
That is different. If you look carefully, what is being inserted is data that is being selected from three other tables. So it's not that the insert is a join, but the insert is OF a join.
(05-26-2016, 08:52 AM)skunkbad Wrote: That is different. If you look carefully, what is being inserted is data that is being selected from three other tables. So it's not that the insert is a join, but the insert is OF a join. Thanks for your explanation. I'd need your idea, I'm sorry for my updated question. How can I insert data to multiple tables in sequence at the same time? (05-26-2016, 06:34 PM)Phally Seng Wrote:(05-26-2016, 08:52 AM)skunkbad Wrote: That is different. If you look carefully, what is being inserted is data that is being selected from three other tables. So it's not that the insert is a join, but the insert is OF a join. Read this part of the docs: https://www.codeigniter.com/user_guide/d...tions.html
(05-26-2016, 07:22 PM)Read this part of the docs: Wrote: https://www.codeigniter.com/user_guide/d...tions.html Thank you for your docs. |
Welcome Guest, Not a member yet? Register Sign In |