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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T20:11:54+00:00 2026-05-28T20:11:54+00:00

I have a rather large mysql table that has the following structure: fieldid |

  • 0

I have a rather large mysql table that has the following structure:

fieldid | recordid | content
----------------------------
 10     |   01     | Google
 10     |   02     | Yahoo
 10     |   03     | Facebook
 20     |   01     | google.com
 20     |   02     | yahoo.com
 20     |   03     | facebook.com
 30     |   01     | Big search engine
 30     |   02     | Other search engine
 30     |   03     | Largest Social Network
 40     |   01     | Search engine
 40     |   02     | Search engine
 40     |   03     | Social Network

Where fieldid is the id for the field (in this case ’10 is the ‘site name’, ’20’ is the ‘site url’, ’30’ is the ‘site description’ and ’40’ is the ‘category’).
Also, recordid is the id for all the fields in a given website (in this case 01 is Google, 02 is Yahoo and 03 is Facebook).

I would like to combine them into the equivalent of a result set (associative array) filtered by a particular ‘category’ such as:

site            |     url            |     description
----------------|------------------------------------------
Google          | google.com         | Big search engine
Yahoo           | yahoo.com          | Other search engine

Where in this case they are filtered by “Search engine”.

I tried

SELECT
recordid,
GROUP_CONCAT( if( fieldID = 10, content, NULL ) ) AS 'site',
GROUP_CONCAT( if( fieldID = 20, content, NULL ) ) AS 'url',
GROUP_CONCAT( if( fieldID = 30, content, NULL ) ) AS 'description',
GROUP_CONCAT( if( fieldID = 40 and content = 'Search engine', content, NULL ) ) AS 'category'
FROM my_table
GROUP BY recordid
HAVING Category IS NOT NULL

Now, although this works, it is very, very slow because there are far more fieldids than the ones I need to process. Does anyone know of a better way to achieve the same result?

Thanks in advance.

  • 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-05-28T20:11:55+00:00Added an answer on May 28, 2026 at 8:11 pm

    I’d use cascading self joins. Something like:

    SELECT t.content AS 'Site', t2.content AS 'URL', t3.content AS 'Description', t4.content AS 'Category'
    FROM my_table AS t
    LEFT JOIN my_table AS t2 ON (t2.recordid = t.recordid AND t2.fieldid = 20)
    LEFT JOIN my_table AS t3 ON (t3.recordid = t.recordid AND t3.fieldid = 30)
    LEFT JOIN my_table AS t4 ON (t4.recordid = t.recordid AND t4.fieldid = 40 AND t4.content = 'Search engine')
    WHERE t.fieldid = 10
    

    Since the WHERE condition is going to significantly reduce the resultset, the query should perform faster, assuming you have appropriate indexes on (fieldid) and (fieldid, recordid).

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

Sidebar

Related Questions

I have a rather large (many gigabytes) table of data in SQL Server that
I have a rather large text file that has a bunch of missing newlines,
I have a large mysql table that I think might be using the wrong
I have a table in MySQL with a large amount of data that I
I have a rather large table that takes about 10-20 seconds to fetch depending
I have rather large input XML files that must be converted to a given
I have a rather large (80k loc) java desktop app that talks to a
I have a rather large list of data that contains 5 properties per element.
I have a rather large DBML file and recently discovered that Visual Studio's MSLinqToSQLGenerator
I have a rather large XSD file and I have heard that it is

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.