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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T05:55:38+00:00 2026-06-08T05:55:38+00:00

I need to flatten out 2 rows in a vertical table (and then join

  • 0

I need to flatten out 2 rows in a vertical table (and then join to a third table) I generally do this by making a derived table for each field I need. There’s only two fields, I figure this isn’t that unreasonable.

But I know that the rows I want back in the derived table, are the subset that’s in my join with my third table.
So I’m trying to figure out the best derived tables to make so that the query runs most efficiently.

I figure the more restrictive I make the derived table’s where clause, the smaller the derived table will be, the better response I’ll get.

Really what I want is to correlate the where clause of the derived table with the join with the 3rd table, but you can’t do that in sql, which is too bad. But I’m no sql master, maybe there’s some trick I don’t know about.

The other option is just to make the derived table(s) with no where clause and it just ends up joining the entire table twice (once for each field), and when I do my join against them the join filters every thing out.

So really what I’m asking I guess is what’s the best way to make a derived table where I know pretty much specifically what rows I want, but sql won’t let me get at them.

An example:

table1
------

id  tag     value
--  -----   -----
1   first   john
1   last    smith
2   first   sally
2   last    smithers


table2
------

id     occupation
--     ----------
1      carpenter
2      homemaker


select table2.occupation, firsttable.first, lasttable.last from
table2, (select value as first from table1 where tag = 'first') firsttable,
(select value as last from table1 where tag = 'last') lasttable
where table2.id = firsttable.id and table2.id = lasttable.id

What I want to do is make the firsttable where clause where tag=’first’ and id = table2.id

  • 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-08T05:55:40+00:00Added an answer on June 8, 2026 at 5:55 am

    I think what you’re asking for is a COMMON TABLE EXPRESSION. If your platform doesn’t implement them, then a temporary table may be the best alternative.

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

Sidebar

Related Questions

Need to apply a filter to a file like this: TUPAC_0006:1:1:2554:2356#0/1 0 * 0
Need a map reduce function by mongo in php This my mongo structure [_id]
Need just a push in the right direction with this. I'm building a multi-language
I need to flatten objects into nested dicts of the object's properties. The objects
I have a requirement to flatten a resultset in an SSIS package - this
I have a feeling this is not an easy task but I need to
So this is a trivial, but hopefully fun question. I need to make a
I am trying to flatten out the contents of a source List to fields
I am working on a project using OpenCV. I need to precisely crop out
I need this Hash {peter => [apple, orange, mango], sandra => [flowers, bike]} convert

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.