1

so I have this code:

$sql = new Zend_Db_Select($db);
$sql->from("j");
$sql->join("k","k.id = j.id",array());
echo $sql;

which results in the query:

SELECT `j`.* FROM `j` INNER JOIN `k` ON k.id = j.id

but I don't just want j.*

I also want k.*

how do I specify zend_db_select for this?

5 Answers 5

2

The third parameter for join() is columns for select. You have passed an empty array.

$sql = new Zend_Db_Select($db);
$sql->from('j');
$sql->join('k','k.id = j.id',array());
echo $sql;

Note: for this condition k.id = j.id you should use LEFT JOIN(->joinLeft(...))

Sign up to request clarification or add additional context in comments.

Comments

1

You can specify the columns in the from method.

$sql->from(array("j" => "j", array("j.*" , "k.*");

Honestly I am not entirely sure but the Zend Documentation says so :)

Comments

0

if you also want k.*, I think you should have
$sql->join("k","k.id = j.id");, without that array() as the third parameter.
From what I know, that third parameter specifies the columns to be selected from k and since you passed an empty array I'm guessing you override that default k.*

Comments

0

You explicitly tells the join that you want no columns returned for k when you pass an empty array to it. Instead use:

$sql = new Zend_Db_Select($db);
$sql->from('j');
$sql->joinLeft('k','k.id = j.id');
echo $sql;

That should produce what you want I think.

Comments

0
$sql=new Zend_Db_Select($db);
$sql->from('j',array(
//here fields you want to get from 'j' Ex. 'j.id'
));
$sql->join('k',
// here your condition
'k.id = j.id',
//here the fields you need from 'k'
array(
//now the array is empty!!You need to specify needed fields.
//Or just remove it.Defaults is "k.*"!

));

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.