This should do the trick:

SELECT
p.*, IF(CHAR_LENGTH(i.pic), 'yes', 'no') as hasImage
FROM
`product` p
LEFT JOIN `images` i ON (i.productid = p.productid)

hasImage will be 'yes' if there is a row and content in the blob, and 
'no' otherwise.

HTH

- Mike

On 3/11/2008 22:40, Michael wrote:
> Thank you to the people who posted solutions to the last question. :-)
>
> To expand on this, is it possible with MySQL to do the following-
>
> I have two tables, both with 'productid' as the primary field.
>
> I need retrieve a few fields from table 1, but I only need to know if a line
> exists and has a BLOB size larger then 0, in table 2.
>
> (By way of explanation, table 1 has product information and table 2 has
> product images - both share the same primary field).
>
> If that line exists and with content I want to activate code within a PHP 'if'
> statement, however I don't actually want to retrieve the field.
>
> And I'd like to do all of this in 1 SQL statement.
>
> Relevant fields within tables-
>
> table 1 (product info)
> - productid (int primary)
> - title_1 (varchar)
> - title_2 (varchar)
> - title_3 (varchar)
>
> table 2 (images)
> - productid (int primary)
> - pic (blob)
>
> >
>    


-- 
Mike Cochrane
Web Team Leader

gardyneHOLT - design partners
18 Beresford Square Newton
PO Box 3340 Auckland New Zealand
p +64 9 300 3155  f +64 9 302 3349  m 021 545 565
skype gardyneholt_mikec
www.gardyneholt.co.nz


--~--~---------~--~----~------------~-------~--~----~
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