In short, I have this SQLite3 query that uses up 30% of CPU when being run.
SELECT s.* ,r.RaagEnglish ,( SELECT w.WriterEnglish FROM Writer w WHERE w.WriterID = ( SELECT MAX(s1.WriterID) FROM Shabad s1 WHERE s1.ShabadID = s.ShabadID ) ) AS WriterEnglish FROM Shabad s ,raag r WHERE r.RaagID = s.RaagID AND s.ShabadID = $SHABADNO ORDER BY ShabadID ASC
I have 3 tables in my Database: Writer, Raag, and Shabad.
A row in Shabad has a WriterID and a RaagID column.
This SQL Query has to get all the Rows in Shabad that match with the Column ShabadID, plus they have to match the WriterID column with WriterEnglish column from the Writer Table. And match RaagID column to RaagEnglish column from the
This is a big query, and I am a SQL n00b, so I would appreciate if someone could help me optimize this query.
In the query above, Shabad is the Article, Raag is the Article Format. Max chooses the maximum value from all of the rows of a specific column.
Here is my DB (no private info, don't worry):