Magento – How to retrieve full customer name with SQL

eavMySQL

Can anyone provide an SQL command that retrieves a customer's first and last name in one row? All my attempts at JOINs have resulted in multiple rows, with first name in one row and last name in the next.

Best Answer

Since attribute ids for first and last name vary between magento instlalations it would be wise to select attribute_id values for first name and last name from eav_attribute and write the query for retrieving first and last name in a single row like this:

SELECT entity_id, group_concat(VALUE SEPARATOR ' ') AS fullname 
FROM customer_address_entity_varchar AS val
INNER JOIN eav_attribute AS attr ON attr.attribute_id  = val.attribute_id
WHERE attr.attribute_code IN ( 'firstname',  'lastname' ) 
GROUP BY entity_id
Related Topic