I have two tables. I try to select some records from one of them. Then, ID's part of that selection should be used to select some records of the other table. For that, I wrote a statement which takes long time for execution. I even couldn't see the results. Also, that broke my phpmyadmin from localhost.
Here is the code:
SELECT * FROM uniquestructures as uns WHERE uns.ProteinID IN (SELECT unp.* FROM uniqueproteins as unp HAVING LENGTH(unp.PDBASequence) < 20) as T)
To make it clear, first it selects records with all columns which have sequence length less than 20. Later, according to IDs of the selected records, I am searching the records have the same ID (as ProteinID)
Thank you very much for your help
I reckon you need to use an
INNER JOIN
with aDISTINCT
here:Also, you might have some joy if you create a separate column on the
uniqueproteins
table to hold the length of thePDBASequence
column (sayPDBASequenceLength
). You could then put an index on thePDBASequenceLength
column rather than callingLENGTH(PDBASequence)
in your query. If the data is not static then create a trigger to populate thePDBASequenceLength
column each time a row is inserted or updated into theuniqueproteins
table. Hence:Your query could then be:
Good luck!