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 8765825
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T16:23:15+00:00 2026-06-13T16:23:15+00:00

i have a question here… i have a 3 tables like this… customer idCustomer

  • 0

i have a question here… i have a 3 tables like this…

customer

idCustomer | namaCustomer | email   | noTelp 
__________________________________________________
1          |  Wawan       | a@a.com | 08985623895

attribute

idAttribute | Name   | publish
______________________________
1           | Gender |  Y
2           | Hobby  |  Y
3           | Job    |  Y
4           | Mission|  N

Customer attribute

idCustomer  |  idAttribute   | value 
_____________________________________
1           |   1            | Male
1           |   2            | Hacking
1           |   3            | IT Support

The question is.. what query statement if i want to get the query from that 3 tables and get the result like this

idCustomer | namaCustomer | email   | noTelp      | Gender  | Hobby   | Job
___________________________________________________________________________________
1          |  Wawan       | a@a.com | 08985623895 | Male    | Hacking | IT Support

So the table column was added from customer attribute data, but before that we must look attribute tabel that the attribute is published or not (looking for publish value)

anyone can help me here???

great thanks before

  • 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-13T16:23:16+00:00Added an answer on June 13, 2026 at 4:23 pm

    Try this:

    SELECT
      c.idCustomer,
      c.namaCustomer,
      c.email,
      c.noTelp, 
      MAX(CASE WHEN a.Name = 'Gender' THEN ca.value END) AS 'Gender',
      MAX(CASE WHEN a.Name = 'Hobby'  THEN ca.value END) AS 'Hobby',
      MAX(CASE WHEN a.Name = 'Job'    THEN ca.value END) AS 'Job'
    FROM Customerattribute ca
    INNER JOIN attribute a ON ca.idAttribute = a.idAttribute
    INNER JOIN Customer c ON c.idCustomer = ca.idCustomer
    GROUP BY ca.idCustomer
    

    SQL Fiddle Demo

    However, for future use of this query for new attributes, you have to do it dynamically like so:

    SET @sql = NULL;
    SELECT
      GROUP_CONCAT(DISTINCT CONCAT('MAX(IF(a.Name = ''',
          a.Name, ''', ca.value, NULL)) AS ',
          a.Name )
      ) INTO @sql
    FROM Customerattribute ca
    INNER JOIN attribute a ON ca.idAttribute = a.idAttribute
    INNER JOIN Customer c ON c.idCustomer = ca.idCustomer
    WHERE a.publish = 'Y';
    
    SET @sql = CONCAT('SELECT  c.idCustomer,  c.namaCustomer, '
      ' c.email, c.noTelp, ', @sql, ' FROM Customerattribute ca',
     ' INNER JOIN attribute a ON ca.idAttribute = a.idAttribute', 
    ' INNER JOIN Customer c ON c.idCustomer = ca.idCustomer',
    ' GROUP BY c.idCustomer');
    
    SELECT @sql;
    
    prepare stmt 
    FROM @sql;
    
    execute stmt;
    

    Dynamic Fiddle Demo

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

Sidebar

Related Questions

Noob question here! I have an array with hashes that looks like this: arr
Newbee question here - I have this method in the view controller m: -(void)
Basic question here - I have many lines of code that look something like:
I have seen this question here, and was wondering if the same method of
I have used this question here on stackoverflow to create a random string without
Hello I have a question here... I'll show you my tables first... [Vendedores]( [IdVendedor]
Good day, I have like 2 question here: First a background information. from the
I have this question here (as well other quesrtions on SO), and the Apple
I have a question here that looks a little like some of the ones
NOTE: I have a related question here (http://stackoverflow.com/questions/6915055/are-jsf-views-shared-between-users) but that deals with a few

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.