Find the attribute_id by attribute_code
$attribute = Mage::getModel('eav/config')->getAttribute('catalog_product', $attributeCode);
$id = $attribute->getId();
if $id
is null
then the attribute does not exist.
It works the same for getting category attributes, customer attributes and customer address attributes.
$attribute = Mage::getModel('eav/config')->getAttribute('catalog_category', 'is_anchor');
$attribute = Mage::getModel('eav/config')->getAttribute('customer', 'gender');
$attribute = Mage::getModel('eav/config')->getAttribute('customer_address', 'postcode');
[EDIT]
Apparently I can't read. I missed the line that stated sql query
.
Here is a query also:
SELECT
e.attribute_id
FROM
eav_attribute e
LEFT JOIN
eav_entity_type t
ON e.entity_type_id = t.entity_type_id
WHERE
e.attribute_code = 'image' AND
t.entity_type_code = 'catalog_product'