SQL How to connect two tables together by a specific column?

时间:2016-02-12 21:59:30

标签: mysql sql phpmyadmin

I have two tables: university and university_list

Table1 - university enter image description here

Table2 - university_list enter image description here

I added var i, out, arr = [{0: 2, 'car': 3}, {1: function(){}, 2:function foo(){}}, 1 ,'bar' , document.body, document.querySelectorAll('body'), window]; var s = performance.now(); for (i = 0; i < 10000; i++) { out = toArray(arr); } var e = performance.now(); //out: [2, 3, function, function, 1, "bar", <body>, <body>, 1, Window] (10) //Passed in ~185ms (Safari 9.0.3) into the table 2 and I need to connect the two tables.

If university_id from table 1 and university_name from table 2 are identical, get the name from table 1 and replace it onto table 2 id

Thank you in advance!

3 个答案:

答案 0 :(得分:4)

PhoneStateListener phoneStateListener = new PhoneStateListener() {
            @Override
            public void onCallStateChanged(int state, String incomingNumber) {
                // TODO Auto-generated method stub
                // super.onCallStateChanged(state, incomingNumber);
                switch (state) {
                case  TelephonyManager.CALL_STATE_RINGING:
                    callStatus=true;
                    while(callStatus)
                    {

                    OnOff();
                    if(state==TelephonyManager.CALL_STATE_OFFHOOK)
                    {
                        break;

                    }

                    }
                    break;
                case  TelephonyManager.CALL_STATE_OFFHOOK:
                    callStatus=false;
                    Off();
                    break;
                default:
                    break;
                }

Above query will return id and name of university if match. Hold both value in variable and pass variable in update query.

select a.id,b.name from table1 as a
inner join table2 as b
on a.university_name = b.name

答案 1 :(得分:2)

It is a simple join update You can update table 2 using below query

^\A\s+[a-zA-Z0-9 ]+$\A\s+
/s*^[a-zA-Z0-9 ]+$/s*

you also can refer to Join Update

答案 2 :(得分:1)

UPDATE university_list a 
JOIN university b ON a.name = b.university_name 
SET a.university_id = b.id