Welcome Guest, Not a member yet? Register   Sign In
Help tuning a very poor SQL query
#6

[eluser]jedd[/eluser]
Okay .. rough draft absent further understanding is this:
Code:
SELECT *
    FROM kg_compounds
    LEFT JOIN kg_progress ON kg_progress.compound=kg_compounds.id
    WHERE grade='$level'
    AND kg_progress.compound_progress=1
UNTESTED, mind. Perhaps something for you to start playing with, at least.

Can I suggest that for foreign keys - for example your kg_progress.compound - that you call them the other table name with a _id suffix.

So rather than kg_progress.compound you'd call it kg_progress.compound_id

I'd also suggest that you try to avoid having column names that are the same as table names - it's just plain confusing, and hints at a badly considered / designed schema. Often renaming the column as 'name' or 'description' is sufficiently descriptive.


Messages In This Thread
Help tuning a very poor SQL query - by El Forum - 06-17-2009, 08:03 AM
Help tuning a very poor SQL query - by El Forum - 06-17-2009, 08:19 AM
Help tuning a very poor SQL query - by El Forum - 06-17-2009, 08:24 AM
Help tuning a very poor SQL query - by El Forum - 06-17-2009, 09:42 AM
Help tuning a very poor SQL query - by El Forum - 06-17-2009, 09:47 AM
Help tuning a very poor SQL query - by El Forum - 06-17-2009, 10:10 AM
Help tuning a very poor SQL query - by El Forum - 06-17-2009, 10:28 AM
Help tuning a very poor SQL query - by El Forum - 06-17-2009, 11:21 AM
Help tuning a very poor SQL query - by El Forum - 06-17-2009, 11:40 AM
Help tuning a very poor SQL query - by El Forum - 06-17-2009, 11:49 AM
Help tuning a very poor SQL query - by El Forum - 06-18-2009, 05:49 AM
Help tuning a very poor SQL query - by El Forum - 06-18-2009, 05:53 AM
Help tuning a very poor SQL query - by El Forum - 06-18-2009, 06:02 AM
Help tuning a very poor SQL query - by El Forum - 06-18-2009, 09:57 AM
Help tuning a very poor SQL query - by El Forum - 06-18-2009, 10:14 AM



Theme © iAndrew 2016 - Forum software by © MyBB