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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T04:05:35+00:00 2026-05-30T04:05:35+00:00

I have these three tables, page table page_id page_title 1 a content table content_id

  • 0

I have these three tables,

page table

page_id    page_title
1          a

content table

content_id   content_text
1            text one
2            text two

content structure table

page_id     content_id     order_in_page
1           1              1
1           2              2

my working sql,

SELECT 
    p.*,
    c.*,
    x.*

FROM pages AS p

LEFT JOIN pages_structures AS x
ON x.page_id = p.page_id

LEFT JOIN  pages_contents AS c
ON c.content_id = x.content_id

WHERE p.page_url = 'a'

result,

page_id   page_title   content_text    order_in_page
1         a            text one        1    
1         a            text two        2

the result I am after

page_id   page_title   content_1   content_2    content_3    content_4
1         a            text one    text two     null         null

How can I make the multi-row result into a single row result?

Or maybe the multi rows result is better and faster than a single row result that I want?

EDIT:

the reason I want a single row result is that I can just call the content_# by doing this,

echo $page['content_1'];

just like I call the title,

echo $page['page_title'];
  • 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-30T04:05:36+00:00Added an answer on May 30, 2026 at 4:05 am

    You can do this quite easily using GROUP BY with an IF statement for each column you want to transpose. When MAX evaluates it will always evaluate a non-null value as greater than NULL.

    SELECT
       page_id,
       page_title, 
       MAX(IF(order_in_page = 1, content_text, NULL)) AS content_1,
       MAX(IF(order_in_page = 2, content_text, NULL)) AS content_2,
       .
       .
       .
    FROM 
       pages AS p LEFT JOIN 
       pages_structures AS x ON x.page_id = p.page_id LEFT JOIN  
       pages_contents AS c ON c.content_id = x.content_id
    WHERE
       p.page_url = 'a'
    GROUP BY page_id
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this page table structure to store all the website page information, page_id
I have a mvc project and on one page there is a table of
I have three tables (lots in reality but these three are the ones I
I have users table. There are three other tables: developers, managers, testers. All of
I have the following dynamically generated table on a page along with other tables
I have two tables: groups and group_members . The groups table contains all the
I have three database tables: Story Id Title Content Category Id Title StoryCategory StoryId
I have a problem with my self-made search page. There is 2 tables: **name
I have a simple three table reference. It looks plain enough. The associations there
My table cells have a font-size of 9pt. Within these table cells there 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.