NYCPHP Meetup

NYPHP.org

[nycphp-talk] MySQL Syntax questions

Kristina Anderson ka at kacomputerconsulting.com
Wed May 28 21:43:37 EDT 2008


Tim, with regard to the second query, I wanted the entire row not just 
the ID...do I need to do two queries to get that?

--Kristina

> On May 28, 2008, at 4:42 PM, Kristina Anderson wrote:
> 
> > I have two questions regarding syntax for MySQL queries.
> >
> > 1.  I have complex queries where there are lots of conditional
> > statements, i.e. SELECT * FROM table WHERE this=this AND that=that 
OR
> > thing=thing OR blah=blah OR foo=foo AND bar=bar OR etc=etc OR
> > thing2=thing2...
> >
> >
> > They are not erroring out but they aren't narrowing the resultset
> > sufficiently...do I need parentheses or is there something else I  
> > need?
> >
> 
> In short: you have to be careful of how expressions are evaluated.   
> More parenthesis are likely the solution.
> 
> 
> > 2.  How can I select the last row inserted from a table WHERE
> > field1=somethingineed and field2 is NULL?
> 
> If you've got an auto_increment field (named "id", perhaps):
> 
> SELECT max(id) as lastId FROM table where feld1='foo' and field2 is 
null
> 
> -Tim
> 
> _______________________________________________
> New York PHP Community Talk Mailing List
> http://lists.nyphp.org/mailman/listinfo/talk
> 
> NYPHPCon 2006 Presentations Online
> http://www.nyphpcon.com
> 
> Show Your Participation in New York PHP
> http://www.nyphp.org/show_participation.php
> 
> 





More information about the talk mailing list