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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T22:26:50+00:00 2026-05-25T22:26:50+00:00

I have a table of preferences, called txp_prefs. I would like to return multiple

  • 0

I have a table of preferences, called “txp_prefs”. I would like to return multiple preferences into a single row; the reason I prefer this to a simple concatenation is that I’m using a plugin in textpattern which can process the single row.

Here is the testing data I have:

------------------------------------------------
|Id | event   | name             |value        |
------------------------------------------------
| 1 | season  | season_start     | 12/10/2011  |
-----------------------------------------------
| 2 | season  | season_end       | 29/10/2011  |
------------------------------------------------
| 3 | season  | season_countdown | 7           |
------------------------------------------------
| 4 | another | test1            | result1     |
------------------------------------------------
| 3 |         | test2            | result2     |
------------------------------------------------

The final result I would like to get is:

----------------------------------------------------------
|event    | season_start | season_end | season_countdown |
----------------------------------------------------------
|season   | 12/10/2011   | 29/10/2011 | 7                |
----------------------------------------------------------

I can (obviously) create the separate queries to get each result independently; for example

SELECT t1.event, t1.val AS season_start FROM txp_prefs t1 WHERE t1.event="season" AND t1.name="season_start" (to get the season_start)
SELECT t2.event, t2.val AS season_end FROM txp_prefs t2 WHERE t2.event="season" AND t2.name="season_end" (to get the season_end)

But I get errors when I try to join the two together, eg like this:

SELECT t1.event, t1.val AS season_start FROM txp_prefs t1 WHERE t1.event="season" AND t1.name="season_start"
LEFT JOIN 
(SELECT t2.event, t2.val AS season_end FROM txp_prefs t2 WHERE t2.event="season" AND t2.name="season_end") t3
ON t1.event=t3.event

The error messages says it is something to do with the join (which I guessed anyway – the two individual queries work.

Any ideas? I have recently figured through joining different tables together, so I assume it is possible to join a table to itself.

  • 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-25T22:26:51+00:00Added an answer on May 25, 2026 at 10:26 pm

    Based on the structure given you can use

    SELECT 
         MAX(CASE WHEN name = 'season_start' THEN value END) AS season_start,
         MAX(CASE WHEN name = 'season_end' THEN value END) AS season_end,
         MAX(CASE WHEN name = 'season_countdown' THEN value END) AS season_countdown
    FROM txp_prefs
    WHERE event='season'
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an SQL table called trainings that looks like this: +-----+-----------+--------+------------+------------+------------+-------+ | Id
i have a table called users this what the table look like CREATE TABLE
I have some table: table ASK with idask table PREFERENCES with idpref , fk_idask
I have table with 50 entries (users with such details like Name Surname Location
I have a problem where the user has set his preferences in a table.
I have a table called Mytable in home/models.py and using django aep I reference
I have a table called Order_List that contains a list of orders. Each column
SQL 2005, 600,000,000 rows. I have a table called Location currently using the data
I am using MySQL Workbench to create a database. I have a table called
I have a table called ApprovalTasks... Approvals has a status column I also have

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.