Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9084079
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T20:55:14+00:00 2026-06-16T20:55:14+00:00

This is a complicated question, so please bear with me. I am using 3

  • 0

This is a complicated question, so please bear with me. I am using 3 different tables to make 1 result set. They are as follows:

customer_address_entity
    entity_id | entity_type_id | attribute_set_id | increment_id | parent_id | create_at | update_at | is_active

customer_entity_int
    value_id | entity_type_id | attribute_id | entity_id | value


customer_address_entity_varchar
    value_id | entity_type_id | attribute_id | entity_id | value

Ok, so now you have the structure, here is my SQL call I have built so far:

SELECT CAE.entity_id, 
       CEI.value AS default_entity_id, 
       CAEV.attribute_id, 
       CAEV.value 
FROM   customer_address_entity AS CAE 
       JOIN customer_entity_int AS CEI 
         ON CEI.entity_id = CAE.parent_id 
            AND CEI.attribute_id = '13' 
       JOIN customer_address_entity_varchar AS CAEV 
         ON CAEV.entity_id = CAE.entity_id 
WHERE  CAE.parent_id = '2328' 
       AND CAE.is_active = 1 

This outputs the following example dataset:

 ID     default  att   value

'1567', '1567', '19', 'John'
'1567', '1567', '21', 'Doe'
'1567', '1567', '23', 'Johns Company'
'1567', '1567', '25', 'Johns City'
'1567', '1567', '26', 'Johns Country'
'1567', '1567', '27', 'Johns State'
'1567', '1567', '29', 'Johns Zip Code'
'1567', '1567', '30', 'Johns Phone'
'1567', '1567', '31', 'Johns Fax'
'1568', '1567', '19', 'Jane'
'1568', '1567', '21', 'Doe'
'1568', '1567', '23', 'Janes Company'
'1568', '1567', '25', 'Janes City'
'1568', '1567', '26', 'Janes Country'
'1568', '1567', '27', 'Janes State'
'1568', '1567', '29', 'Janes Zip'
'1568', '1567', '30', 'Janes Phone'
'1568', '1567', '31', 'Janes Fax'
'1569', '1567', '19', 'Frank'
'1569', '1567', '21', 'Frunz'
'1569', '1567', '23', 'Franks Company'
'1569', '1567', '25', 'Franks City'
'1569', '1567', '26', 'Franks Country'
'1569', '1567', '27', 'Franks State'
'1569', '1567', '29', 'Franks Zip'
'1569', '1567', '30', 'Franks Phone'
'1569', '1567', '31', 'Franks Fax'

The final part of this code, I would like to create X number (in this case 3) of ROWS based on the number UNIQUE entity_id (Column 1 in returned data set ie .1567,1568 and 1569). The intended end result being:

'1567', '1567', 'John', 'Doe', 'Johns Company', 'Johns City', 'Johns State', 'Johns Zip Code', 'Johns Phone', 'Johns Fax'
'1568', '1567', 'Jane', 'Doe', 'Janes Company', ...  etc
'1569', '1567', 'Frank', 'Franz', 'Franks Comapny', ...   etc        

Is this even possible?

EDIT Thanks to Gordon Linoff — The answer is elegant and simple! I threw in a few edits of my own, but will be accepting Gordons answer and voting it up. Here are the edits I made, which work beautifully!!

select entity_id,
   if(entity_id = default_entity_id, 'true', 'false') as default_entity,
   max(case when attr = '19' then `value` end) as `FirstName`,
   max(case when attr = '21' then `value` end) as `LastName`,
   max(case when attr = '23' then `value` end) as `CompanyName`,
   max(case when attr = '25' then `value` end) as `City`,
   max(case when attr = '27' then `value` end) as `State`,
   max(case when attr = '29' then `value` end) as `ZipCode`,
   max(case when attr = '30' then `value` end) as `PhoneNumber`,
   max(case when attr = '31' then `value` end) as `Fax`

from (SELECT CAE.entity_id, CEI.value AS default_entity_id, CAEV.attribute_id AS attr, CAEV.value 
  FROM   customer_address_entity CAE 
         JOIN customer_entity_int CEI 
           ON CEI.entity_id = CAE.parent_id 
              AND CEI.attribute_id = '13' 
         JOIN customer_address_entity_varchar CAEV 
           ON CAEV.entity_id = CAE.entity_id 
  WHERE  CAE.parent_id = '2328' 
         AND CAE.is_active = 1
 ) as t
group by entity_id
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-16T20:55:15+00:00Added an answer on June 16, 2026 at 8:55 pm

    You can do this with a group by:

    select entity_id,
           MAX(default) as default,
           max(case when att = '19' then value end) as FirstName,
           max(case when att = '21' then value end) as LastName,
           max(case when att = '23' then value end) as CompanyName,
           max(case when att = '25' then value end) as City,
           max(case when att = '27' then value end) as State,
           max(case when att = '29' then value end) as ZipCode,
           max(case when att = '30' then value end) as PhoneNumber,
           max(case when att = '31' then value end) as Fax
    from (SELECT CAE.entity_id, CEI.value AS default_entity_id, CAEV.attribute_id, CAEV.value 
          FROM   customer_address_entity CAE 
                 JOIN customer_entity_int CEI 
                   ON CEI.entity_id = CAE.parent_id 
                      AND CEI.attribute_id = '13' 
                 JOIN customer_address_entity_varchar CAEV 
                   ON CAEV.entity_id = CAE.entity_id 
          WHERE  CAE.parent_id = '2328' 
                 AND CAE.is_active = 1
         ) t
    group by entity_id
    

    This process is called pivoting and aggreagtion is one solution (some databases have a pivot keyword for this). This assumes that each value appears only once per entity. Also, if a value is not present, it will get the value NULL.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

It's a long question but not too complicated so please bear with me. I'm
This is quite a complicated and brain busting question, so please read carefully and
Hey folks, this question can't be too complicated. Please provide a solution to at
This question follows on from a question I asked yesterday about why using the
This design question needs a bit of context, so please bear with me. I
In this question, I had help in simplifying and forming a valid complicated JSON
Please bear with me Silverlight Designer Gurus, this is compicated (to me). I'm creating
Hi this is a little complicated so please let me know if any of
this sounds like a really simple question but could easily have a very complicated
EDIT: This got way too complicated, I will migrate this question to another question

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.