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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T10:06:50+00:00 2026-06-18T10:06:50+00:00

I have several tables in my database and want to select a couple columns

  • 0

I have several tables in my database and want to select a couple columns from a couple tables, which is all fine. Now, there is a 3rd table, and this table has a column that has different text values in it, but the same few “text_values” for different users, for instance:

table3

row userid  text_value  value
1   user1   text1       value1
2   user1   text2       value2
3   user2   text1       value3
4   user3   text1       value4
...

Now, I want to take INFO1 and INFO2 from Table1, INFO3 and INFO4 from Table2, but then I want to take all the values from Table3 where text_value=text1 and make this a 5th column with INFO5, and then take values from Table3 where text_value=text2 and make this a 6th column with INFO 6.

I have the following query, which WORKS fine if I ONLY want the INFO5 column:

SELECT Table1.INFO1, Table1.userid , Table2.INFO2,
Table1.INFO3, Table2.INFO4,
Table3.value AS INFO5
FROM Table1 LEFT OUTER JOIN Table2 ON Table1.userid = Table2.userid 
LEFT OUTER JOIN Table3 ON Table1.userid = Table3.userid 
WHERE Table3.text_value = 'text1' 

However, I want to have another column created using the values from the same table3 VALUE column, but when TEXT_VALUE = ‘text2’ (this is true for ‘text3’, ‘text4’, as there are several texts to “filter” on).

When I change the query to the following, it doesn’t work:

SELECT Table1.INFO1, Table1.userid , Table2.INFO2,
Table1.INFO3, Table2.INFO4,
Table3.value AS INFO5 WHERE Table3.text_value = 'text1' 
Table3.value AS INFO6 WHERE Table3.text_value = 'text2' 
FROM Table1 LEFT OUTER JOIN Table2 ON Table1.userid = Table2.userid 
LEFT OUTER JOIN Table3 ON Table1.userid = Table3.userid 

Any guidance will be 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-18T10:06:52+00:00Added an answer on June 18, 2026 at 10:06 am

    You need a CASE there:

    SELECT  Table1.INFO1, 
            Table1.userid, 
            Table2.INFO2,
            Table1.INFO3, 
            Table2.INFO4,
            CASE WHEN Table3.text_value = 'text1' THEN Table3.value END AS INFO5 
            CASE WHEN Table3.text_value = 'text2' THEN Table3.value END AS INFO6 
    FROM Table1 
    LEFT OUTER JOIN Table2 
        ON Table1.userid = Table2.userid 
    LEFT OUTER JOIN Table3 
        ON Table1.userid = Table3.userid 
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a database table with several columns in it. I want to select
I have a database with several hundred tables imported from a third source. Using
I have several hosts from which i want to do the same query. So
Database Name is ONLINEEXAM I have several tables in the db and I want
I have several database tables that just contain a single column and very few
I have an Access database (in Access 2003) with several tables, and data must
Let's say we have system A comprising a MySQL database, with several tables. After
I have several tables that I am selecting data from. I am trying to
I have several tables that I want to put side by side, however when
I have a SQL Server 2005 database with several tables. One of the tables

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.