« Return to Thread: Zend_Db_Select Question
David thanks very much.
Both worked in their own ways and both
were so simple
Pretty embarrassing that should have been
something I thought of.
Once again thanks for the fresh set of
eyes as well as quick responses.
From: David Muir [mailto:david@...]
Sent: Sunday, May 17, 2009 10:15
PM
To: Brandon Peacey
Cc: fw-core@...
Subject: Re: [fw-core]
Zend_Db_Select Question
Then do:
$select->Where('NOT shift_id = ?',
$shiftID);
Unless you're relying on operator precedence, then there's no difference
between the above and what I wrote below.
However, I don't think either will actually work in this case as you're testing
a result from an aggregate function, so it needs to be in a HAVING clause.
Cheers,
David
Brandon Peacey wrote:
I’m trying to invoke the AND NOT clause like so.
WHERE label = ‘N1 SL’ AND NOT
shift_id = 5
I could just write a select statement, however
I like the programmatic approach
of Zend_Db_Select as well as the
flexibility.
From: David Muir [david@...]
Sent: Sunday, May 17, 2009 9:22 PM
To: Brandon Peacey
Cc: fw-core@...
Subject: Re: [fw-core]
Zend_Db_Select Question
Won't this do?
$select->Where('shift_id != ?',
$shiftID);
David
Brandon Peacey wrote:
Hello, I have a question about Zend_Db_Select:
My question, does Zend_Db_Select have an option to
where you can add an AND NOT clause like so.
SELECT COUNT(shift_id) as total FROM location_shifts
WHERE location_id = '1' AND label = 'N1 SL' AND NOT shift_id = '5'
I currently have the select query setup like this.
$select =
$this->select();
$select->from($this->_name,
array('total' =>
new Zend_Db_Expr('COUNT(shift_id)')))
->where('label = ?', $label);
if ($locationID)
$select->where('location_id = ?',
$locationID);
if ($shiftID)
$select->Where('shift_id = ?',
$shiftID);
$select->limit(1);
And this is the generated
output
SELECT COUNT(shift_id) AS `total` FROM `location_shifts`
WHERE (label = 'N1 SL') AND (location_id = 1) AND (shift_id = 5) LIMIT 1
Thank you for your time in advanced
f
« Return to Thread: Zend_Db_Select Question
| Free embeddable forum powered by Nabble | Forum Help |