Reputation: 1
I have 2 tables.
VoiceZone1
: It contains 4 columns(Uname, TID, Res_Msg, Req_Time)VoiceZone2
: It also contains ( Uname, TID, Res_Msg, Req_Time)Having another table VoiceZoneLog
.
Want to copy all columns of VoiceZone1
to VoiceZoneLog
and two columns Res_Msg
, Req_Time
of VoiceZone2
to VoiceZoneLog
table.
Please Guide me using sql/mysql.
Give a Look to my query:
INSERT INTO VoiceZoneLog
SELECT A.REQ_TIME,
B.RES_TIME,
A.USER_NAME,
A.TID,
A.REQ_MSG,
B.RES_MSG
FROM VoiceZone1 A,
VoiceZone2 B
WHERE A.TID=B.TID AND
A.REQ_MSG='CALL_LOGS_HISTORY 14'
So it executed properly but my task is want to optimize it. I want any other way. So Please guide me.
Upvotes: 0
Views: 64
Reputation: 1269443
Your query is fine, although it would be better written using standard join syntax and listing the columns for the insert
:
INSERT INTO VOICEZONE_LOGS (REQ_TIME, RES_TIME, USER_NAME, TID, REQ_MSG_A, REQ_MSG_B)
SELECT A.REQ_TIME, B.RES_TIME, A.USER_NAME, A.TID, A.REQ_MSG, B.RES_MSG
FROM VZ_LOGS_REQ A join
VZ_LOGS_RESP B
ON A.TID = B.TID
WHERE A.REQ_MSG='CALL_LOGS_HISTORY 14';
(The column names might be wrong in the insert, I just guessed.)
You can improve performance by having indexes. I would recommend: vz_logs_req(req_msg, tid)
and vs_logs_resp(tid)`.
Upvotes: 3