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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T13:06:39+00:00 2026-06-12T13:06:39+00:00

I have a database with two tables, component_psar and tbl_info. The component_psar table has

  • 0

I have a database with two tables, component_psar and tbl_info. The component_psar table has the field ‘tbl_id’ which references the corresponding ‘id’ field in tbl_info.

I need to write a query in which data is taken from tbl_info and used as the heading for that column in component_psar.

So if the component_psar table contained the data:

tbl_id | col_1
1      |  Hello
1      |  Hi
1      |  What's up?

And then the tbl_info table:

id | heading
1  | Greetings

I would like it to display as:

Greetings
Hello
Hi
What's up?

I’ve written the following SQL query to try and accomplish this:

SELECT component_psar.col_1 as (SELECT tbl_info.heading FROM tbl_info, component_psar WHERE tbl_info.id = '1') FROM tbl_info, component_psar WHERE (component_psar.tbl_id = '1')

But this just throws a syntax error:

#1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '(SELECT tbl_info.heading FROM tbl_info, component_psar WHERE tbl_info.id = compo' at line 1

Can anyone offer any suggestions as to how I might accomplish this? Looking at other questions has led me to reading into pivot tables but I haven’t seen any way in which this might work for my purposes. Perhaps I’m misunderstanding it.

Any help with this would be much appreciated.

  • 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-12T13:06:40+00:00Added an answer on June 12, 2026 at 1:06 pm

    I would try to separate out the process of retrieving data from the database and formatting it for display.

    A simple inner join should work for your query

    select tbl_info.heading as Heading,component_psar.col_1 as Value 
    from tbl_info 
    inner join component_psar on component_psar.tbl_id = tbl_info.id
    order by tbl_info.heading
    

    this will give you the following query results

    Heading   | Value 
    ----------+--------------
    Greetings |  Hello
    Greetings |  Hi
    Greetings |  What's up?
    

    How you process this for display depends your programming environment.

    if your are just printing to the screen the following pseudo code will show how to print the heading only when it changes

    current_heading = ""
    for each row in results
        if row.heading not equal to current_heading   
            current_heading  = row.heading
            print blank line 
            print current_heading 
        end if
        print row.value
    loop
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a database two tables and a linking table that I need a
I have a database framework where I have two tables. The first table has
I have database which has two tables post: id post_name post_desc files: file_id file_name
I have two database tables: 'MyTable' which has a standard auto-incrementing primary key integer
Basically I have a database with two tables, that is, Updates table and Images
I have a database that which contains two tables, links and tour. Tour is
I have a database with two tables, Users and Posts. I'd like to write
I have a database with two tables (Table1 and Table2). Table1 has one column
I have two database tables. One table stores data for a commitment that a
I have a database with two tables, events and tickets . The events table

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.