1

I have a table Called phones contains all members phone numbers each member has unique id and there is another table called posts the posts table has many rows each post has its member id and another cells

I need to collect all members IDs from the posts table depending on the branches cell and delete from phones table where the members ids collected from the posts table

I tried this but it give me error message that mysql server lost the connection

delete from `phones` where `mid` in(select `uid` from `posts` where `branches` = 'contact');

Note: I'm using mysql workbench with my local server

UPDATED

this query also worked after I setup the Preferences below

Go to Edit -> Preferences -> SQL Editor and increase the parameter: DBMS connection read time out (in seconds). For instance: 86400.

Close and reopen MySQL Workbench. Kill your previously query that probably is running and run the query again.

Thanks to @scaisEdge

3
  • Query is correct, not sure why connection is being lost. Are these huge tables? if so probably the select query is taking too long due to lack of an index on branches? Commented Jul 9, 2017 at 18:36
  • the tables are huge and branches column dose not have index Commented Jul 9, 2017 at 18:54
  • @mohamad, you are beating around the bushes. If the table is huge and no index on branches, the entire table will be scanned and depending on the hardware and resources available to MySQL, it may take much longer than DB connection timeout. Have the indexes, your query is correct. Commented Jul 9, 2017 at 19:22

1 Answer 1

1

your query seems correct .. anyway you can try with a inner join

delete  `phones`.*
from `phones` 
inner join `posts`  on `phones`.`mid`  = `posts`.`uid` 
        and `posts`.`branches` = 'contact'

the inner join don't use a IN clause so you can bypass the involved limitation

if the error persist try increment the read time out

Go to Edit -> Preferences -> SQL Editor and icrease the parameter: DBMS connection read time out (in seconds). For instance: 86400.

Close and reopen MySQL Workbench. Kill your previously query that probably is running and run the query again.

Sign up to request clarification or add additional context in comments.

10 Comments

Not sure why this would work and not the one posted in the question?
@AllenKing if the number of elem in IN clause is high you can reach the limit .. so inner join avoid this condition
ok. My suspicion is that proper indexes are not set. So even a join is not guaranteed to work. Poor indexes can only be fixed by putting proper indexes on tables :-)
could be .. but poor index impact on performance .. max_packect_size . impact on the volume onof data involved ..
@scaisEdge Error Code: 2013. Lost connection to MySQL server during query
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.