5

I have this query:


SELECT g.title, g.asin, g.platform_id, r.rank
        FROM games g
        INNER JOIN ranks r ON ( g.id = r.game_id )
        ORDER BY r.rank DESC
        LIMIT 5`

Now, this is my JOIN using Zend_Db_Select but it gives me array error


$query = $this->select();
        $query->from(array('g' => 'games'), array());
        $query->join(array('r' => 'ranks'), 'g.id = r.game_id', array('g.title', 'g.asin', 'g.platform_id', 'r.rank'));
        $query->order('r.rank DESC');
        $query->limit($top);
        $resultRows = $this->fetchAll($query);
        return $resultRows;

Anyone know what I could be doing wrong? I want to get all the columns in 'games' to show and the 'rank' column in the ranks table.

1
  • What's the actual error text? Commented Aug 19, 2009 at 20:39

4 Answers 4

10

I am going to assume you've solved this, but it would be nice to leave the answer for others.

Add this below the instantiation of the select object.

$query->setIntegrityCheck(false);
Sign up to request clarification or add additional context in comments.

1 Comment

5

You could also type fewer characters....

$query = $this->select()
              ->from(array('g' => 'games'), array('title', 'asin', 'platform_id'))
              ->join(array('r' => 'ranks'), 'g.id = r.game_id', array('rank'))
              ->order('r.rank DESC')
              ->limit($top);
return $this->fetchAll($query);

Good luck!

1 Comment

Thanks for this. This was a great help in solving problem with same column names in joined tables.
0

Here's how I'd write it:

$query = $this->select();
$query->from(array('g' => 'games'), array('title', 'asin', 'platform_id'));
$query->join(array('r' => 'ranks'), 'g.id = r.game_id', array('rank'));
$query->order('r.rank DESC');
$query->limit($top);
$resultRows = $this->fetchAll($query);
return $resultRows;

Comments

0

Other example:

select n.content, n.date, u.mail 
from notes n, users u
where n.id_us=u.id and reminder=current_date

$query = $this->select()
    ->from(array('n'=>'notes'), 
      array('content', 'date'))
    ->join(array('u'=>'users'), 'n.id_us=u.id and n.reminder=current_date',
      array('mail'))
    ->setIntegrityCheck(false);
return $this->fetchAll($query);

That's work fine :)

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.