On Mon, 03 Nov 2008 23:01:34 Dalibor Andzakovic wrote:
> > SELECT * FROM table1 LEFT JOIN table2 ON (table1.productid =
> > table2.productid) WHERE table1.productid = '$id'
> >
> > Will get all the records from table1 and matching fileds from table
> 2. Then
> > in you php code you can do
> >
> > While($row = mysqli_fetch_assoc()){
> >         If(sizeof($row['blob'] > 0){
> >                 // do something with blob
> >         }
> > }
> >
> > HTH
> >
> > Dali
>
> Thanks, however is it possible to find out what we need to know about
> the blob
> field (Does it exist and have content?) without actually 'select'ing it
> and
> thus introducing it in to the result set?
>
> I am wondering if this will give optimised performance.

Following code makes kittens cry...

SELECT * FROM table1 LEFT JOIN (SELECT productid, 1 AS gotblob FROM table2 
WHERE blob IS NOT NULL) AS sel ON (table1.productid = sel.productid)

And in PHP
While($row = mysqli_fetch_assoc()){
        If(row['hasblob'] == 1){
                Mysqli_select("SELECT * FROM table2 WHERE productid = 
'$row[productid]'");
                // etc etc
      }
}

I suspect you'd be worse off doing a separate SELECT to fetch the blob field so 
do some benchmarks. This is probably a good example of premature 
eja^H^H^Hoptimisation

dali


--~--~---------~--~----~------------~-------~--~----~
NZ PHP Users Group: http://groups.google.com/group/nzphpug
To post, send email to [email protected]
To unsubscribe, send email to
[EMAIL PROTECTED]
-~----------~----~----~----~------~----~------~--~---

Reply via email to