I have one table with 50,000 records.
In my website, i will let user to select this records by certain criteria, and display on match records. May be just 2000 records match, may be 30,000 records match, depands on the criteria search.
The query is like below:
SELECT a.*, Month(birth_date) as BirthMonth,
year(now())- year(birth_date) as Age
, concat(a.first_name, ' ', a.last_name, ' ', a.nick_name,' '
, ifnull(b.job_desc, ' '), ' ', ifnull(c.area_desc, ' '), ' ', a.designation) as search, b.job_desc, c.area_desc
FROM Member a
LEFT JOIN JobIndustry b ON
a.job_code = b.job_code
LEFT JOIN Area c ON
a.area = c.area_code
LEFT JOIN company d ON a.co_code = d.co_code
Where member_code not in (select member_code from MemberGrp where grp_code = "Favourite")
and search like "%Account%Shelly";
If user select to add all to group, i will insert all this match record to MemberGrp table.
My Question is
1. How to optimize my sql statement ?
2. What method should i use to insert all this match records?
Use "Insert into" and select again the record in then insert statement
or
loop the result from grid and insert one by one?
My main consideration here in performance.
looking for your advice.
Thank in advance