简体   繁体   中英

how to insert from exist table?

INSERT INTO tbl_harga_agen (  id_jenis, id_type, harga, type, id_agen ) 
SELECT  tbl_type_tiket.id_jenis, tbl_type_tiket.id_type, tbl_type_tiket.harga, tbl_type_tiket.type
FROM    tbl_type_tiket left join tbl_agen
WHERE   tbl_type_tiket.id_jenis = tbl_type_tiket.id_jenis
SELECT LAST_INSERT_ID() as id_agen FROM tbl_agen

what wrong with this ?

Missing the join condition, and your where( WHERE tbl_type_tiket.id_jenis = tbl_type_tiket.id_jenis ) clause is not necessary. Also you have five columns specified in in the insert into but are only selecting four columns. You need to fix that and you are the only person who knows the column names so please add that to you select query.

INSERT INTO tbl_harga_agen (  id_jenis, id_type, harga, type, id_agen ) 
SELECT  tbl_type_tiket.id_jenis, tbl_type_tiket.id_type, tbl_type_tiket.harga, tbl_type_tiket.type
FROM    tbl_type_tiket left join tbl_agen on tbl_type_ticket.id_jenis = tbl_agen.id_jenis

Take a read on the "Join syntax" as well: http://dev.mysql.com/doc/refman/5.0/en/join.html

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM