Why am I getting only one result with the following query?

$query = craft()->db->createCommand();
$entryRecord = $query->select('craft_content.field_releaseDate, craft_content.title, craft_entries.id, craft_entries.dateCreated')->from('content')->join('entries', 'craft_content.elementId = craft_entries.id')->where('craft_entries.sectionId=2')->queryRow();

Also the documentation says that the table prefix isn't required, but this doesn't work most of the time, weird.


Completely untested but it looks like you're just querying a row instead of all.

Update queryRow() to queryAll()


The table prefix isn't required, and will mess up your results if you add it.

However, when you refer to a new table (as in "join"), you'll want to alias the table for consistent use:

join('entries entries', 'content.elementId = entries.id')

The first entries is your table reference (sans prefix).

The second entries is your new alias, referenced by entries.id.

Regardless, Peter's answer is spot on.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.