[thelist] SQL Query Review

Randal Rust randalrust at gmail.com
Mon Apr 21 20:18:41 CDT 2008

I have this query that fetches a record for an online encyclopedia.
Does anyone see any efficiencies that I could make? This is a MySQL
database, and we use PHP. This query is executed in a class method
called viewEntry(). There are two arguments passed to the method. The
first is the database connection, $db. The second is the record that I
want, $value. So the method looks like this: $entry->viewEntry($db,
$value) when it is called.


select e.entryID, e.entryTitle, e.category, e.subcategory,
e.narrative, e.firstName, e.lastName, e.middleName, e.topic,
e.subtopic, cdc.description, cds.description, cdt.description,
cdst.description, e.linkTitle, e.entryStatus, e.suffix, e.nickname,
e.previewText, e.altFirstName, e.altMiddleName, e.altLastName,
e.altSuffix, e.altNativeName, e.dateCreated, e.dateChanged,
e.alternateLink, e.latitude, e.longitude from entries e

inner join cd_categories cdc on e.category=cdc.code
left join cd_subcategories cds on e.subcategory=cds.code
left join cd_entry_topics cdt on e.topic=cdt.code
left join cd_subtopics cdst on e.subtopic=cdst.code

where entryID='$value'

Randal Rust
R.Squared Communications

More information about the thelist mailing list