MySQL Forums
Forum List  »  PHP

@Pablo Ghi - Join 2 tables and store in 3rd table (SOLVED)
Posted by: sorav garg
Date: August 06, 2017 07:23AM

I have following 2 tables

¦---bb_tickets---¦
¦ id ¦ owner ¦
¦----------------¦
¦ 111 ¦ 2 ¦
¦ 145 ¦ 2 ¦
¦ 152 ¦ 3 ¦
¦----------------¦


¦---bb_users-----¦
¦ id ¦ user ¦
¦--------------- ¦
¦ 1 ¦ Admin ¦
¦ 2 ¦ PG ¦
¦ 3 ¦ FS ¦
¦----------------¦


i'd like to export in the 3rd table following data:


¦----Result----¦
¦ id ¦ user ¦
¦--------------¦
¦ 111 ¦ PG ¦
¦ 145 ¦ PG ¦
¦--------------¦


My Table structure -

CREATE TABLE `bb_result` (
`id` int(11) NOT NULL,
`bb_tickets_id` int(11) NOT NULL,
`user_name` text NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=latin1;

CREATE TABLE `bb_tickets` (
`main_id` int(11) NOT NULL,
`id` int(11) NOT NULL,
`owner` int(11) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=latin1;

CREATE TABLE `bb_users` (
`id` int(11) NOT NULL,
`user` text NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=latin1;


Query to insert data in 3rd table using joins -

INSERT INTO bb_result (bb_tickets_id,user_name) SELECT T.id,U.user FROM bb_tickets AS T INNER JOIN bb_users AS U ON T.owner = U.id WHERE T.owner = 2


Hope this will helps you.

Thanks

Options: ReplyQuote


Subject
Written By
Posted
@Pablo Ghi - Join 2 tables and store in 3rd table (SOLVED)
August 06, 2017 07:23AM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.