<p>The table prefix <em>isn't</em> required, and will mess up your results if you add it.</p>

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

<pre><code>join('entries entries', 'content.elementId = entries.id')
</code></pre>

<p>The first <code>entries</code> is your table reference (sans prefix).</p>

<p>The second <code>entries</code> is your new alias, referenced by <code>entries.id</code>.</p>

<p>Regardless, <a href="https://craftcms.stackexchange.com/a/4723/45">Peter's answer</a> is spot on.</p>

CC BY-SA 3.0
2014-11-13T21:51:32.217Z
2014-11-13T21:51:32.217Z
2017-04-13T12:51:00.303Z
Lindsey D
<p>Completely untested but it looks like you're just querying a row instead of all.</p>

<p>Update <code>queryRow()</code> to <code>queryAll()</code></p>

CC BY-SA 3.0
2014-11-13T21:48:11.407Z
2014-11-13T21:48:11.407Z
Peter Tell
<p>Why am I getting only one result with the following query?</p>

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

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

<plugin-development><plugins><database>
Why am I getting only one result with "craft()->db->createCommand()"?
# Why am I getting only one result with "craft()->db->createCommand()"?

(Asked by: username_0 on 2014-11-13)

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.

**Tags:** plugin-development, plugins, database


---

## 2 answers

### Answer by username_2 on 2014-11-13. Score: 7 | Accepted answer

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

Update `queryRow()` to `queryAll()`


---

### Answer by username_1 on 2014-11-13. Score: 4

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.


---

