Created
March 7, 2014 13:17
-
-
Save tegansnyder/9411304 to your computer and use it in GitHub Desktop.
Magento - Grab Customer first and last name raw sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
SELECT `e`.*, | |
`at_prefix`.`value` | |
AS `prefix`, | |
`at_firstname`.`value` | |
AS `firstname`, | |
`at_middlename`.`value` | |
AS `middlename`, | |
`at_lastname`.`value` | |
AS `lastname`, | |
`at_suffix`.`value` | |
AS `suffix`, | |
Concat(IF(at_prefix.value IS NOT NULL | |
AND at_prefix.value != '', | |
Concat(Ltrim(Rtrim(at_prefix.value)), ' '), | |
''), Ltrim(Rtrim(at_firstname.value)), ' ', IF( | |
at_middlename.value IS NOT NULL | |
AND | |
at_middlename.value != '', Concat(Ltrim(Rtrim(at_middlename.value)), ' ') | |
, ''), | |
Ltrim(Rtrim(at_lastname.value)), IF(at_suffix.value IS NOT NULL | |
AND at_suffix.value != '', Concat(' ', Ltrim(Rtrim(at_suffix.value))), '' | |
)) AS | |
`name` | |
FROM `customer_entity` AS `e` | |
LEFT JOIN `customer_entity_varchar` AS `at_prefix` | |
ON ( `at_prefix`.`entity_id` = `e`.`entity_id` ) | |
AND ( `at_prefix`.`attribute_id` = '4' ) | |
LEFT JOIN `customer_entity_varchar` AS `at_firstname` | |
ON ( `at_firstname`.`entity_id` = `e`.`entity_id` ) | |
AND ( `at_firstname`.`attribute_id` = '5' ) | |
LEFT JOIN `customer_entity_varchar` AS `at_middlename` | |
ON ( `at_middlename`.`entity_id` = `e`.`entity_id` ) | |
AND ( `at_middlename`.`attribute_id` = '6' ) | |
LEFT JOIN `customer_entity_varchar` AS `at_lastname` | |
ON ( `at_lastname`.`entity_id` = `e`.`entity_id` ) | |
AND ( `at_lastname`.`attribute_id` = '7' ) | |
LEFT JOIN `customer_entity_varchar` AS `at_suffix` | |
ON ( `at_suffix`.`entity_id` = `e`.`entity_id` ) | |
AND ( `at_suffix`.`attribute_id` = '8' ) | |
WHERE ( `e`.`entity_type_id` = '1' ) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment