简体   繁体   中英

Sql connect three tables

I have a table1,table 2 and a table 3 where I would like to insert data from one table to another. The application is about a recruitment system. The t1 is the table that contain a username and a password

t1
----------
ID  USERNAME   PASSWORD  

The table 2 contains the basic information of the applicant

 t2
----------
ID  ID_t1  NAME LASTNAME BIRTH POSITION

The table 3 contains information about the skills
t3
----------
ID  ID_t1  ID_t2  SKILLS DEGREE EXPERIENCE

So, I want to store in t3 the ID of the t1 and the ID of the the t2. I need three tables because depending on position the system must store the values in different table.. For instance if the user choose potition for cashier system will show different fields, but if the user also wants a potision for personal assistant too the system store only the skills information.

How can I store them with the INSERT query?

an INSERT ... SELECT statement can solve the problem. Although not tested, the following SQL code may can combine values from two tables into one.

INSERT INTO t3 (ID_t1, ID_t2)
  SELECT t1.ID, t2.ID
  FROM t1, t2 WHERE t2.ID_t1 = t1.ID

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