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

  • Home
  • SEARCH
  • 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 7824995
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T08:47:28+00:00 2026-06-02T08:47:28+00:00

I have data stored in a MySQL database according to the Entity-Attribute-Value pattern (EAV),

  • 0

I have data stored in a MySQL database according to the Entity-Attribute-Value pattern (EAV), specifically user profile values from Drupal 6. I would need an SQL query or view to get the data as a normal relational table. The tables have the following layout:

Table: users
user_id   username 
---------------------
1         steve
2         michelle


Table: profile_fields
field_id   field_name
------------------------
1          first_name
2          last_name


Table: profile_values
field_id   user_id   value
---------------------------
1          1         Steve
2          1         Smith
1          2         Michelle
2          2         Addams

And I would need to somehow get the following result from a query:

user_id    first_name    last_name
-----------------------------------
1          Steve         Smith
2          Michelle      Addams

I have understood this is impossible to do in a single SQL query in the general case. But this is not the general case, and I have two advantages:

  • I know the content of the “profile_fields” table, and I am 100% sure that this data will not change for the time period that this query will be used.
  • It doesn’t have to be in a single query – it can be a query, some PHP code to analyze the results and then another query.
  • 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-02T08:47:31+00:00Added an answer on June 2, 2026 at 8:47 am

    This can be done in a sql query using columnar subqueries as follows:

    SELECT 
      u.user_id, 
      (select value from profile_values f1 WHERE f1.field_id=1 and u.user_id=f1.user_id) AS first_name, 
      (select value from profile_values f2 WHERE f2.field_id=2 and u.user_id=f2.user_id) AS last_name
      FROM users u 
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have data stored as below in an MS Access database: Date User 20090101
I have the following scenario: I have various user's data stored in my database.
I have a MySQL database with a date_of_birth field. The data stored in this
I have a bunch of data stored in a MySQL database with a column
I have a PHP web site with data stored in a MySql database. (approximately
I have stored some data in MySQL database through a java program. Now I
I have AES encrypted data stored in the database using php mysql. Which I
I have a database which contains picture data stored as a binary blob. The
I have a data structure where an entity has times stored as an int
I have a table in my database to store user data. I found a

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.