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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T03:59:07+00:00 2026-05-20T03:59:07+00:00

I have a schema that is setup as so: Cards (card_id, fact_id, fact_view_id) data_for_fact

  • 0

I have a schema that is setup as so:

Cards         (card_id, fact_id, fact_view_id)
data_for_fact (fact_id, key, value)

Sample data:

  [cards]:  (51, 1, '2::1'), (52, 1, '2::2') ...
  [data_for_fact]: (1, 'q', 'person'), (1, 'a', 'noun')

The intended output is:

 [cards]: (51, 'person' (as q), 'noun' (as a)), 
          (52, 'noun' (as q), 'person' (as a))

With SQL Lite, how can I get the output that I’m looking for?

I’ve tried creating a join, but that only works on the first output card. The difference between the two cards are the fact_view 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-05-20T03:59:07+00:00Added an answer on May 20, 2026 at 3:59 am

    You could do it with a union:

    SELECT card_id, ques.value AS q, ans.value AS a
        FROM cards
        JOIN data_for_fact AS ques 
          ON cards.fact_id=ques.fact_id AND ques.key='q'
        JOIN data_for_fact AS ans 
          ON cards.fact_id=ans.fact_id AND ans.key='a'
        WHERE cards.fact_view_id='2::1'
    UNION ALL
    SELECT card_id, ans.value AS q, ques.value AS a
      FROM cards
        JOIN data_for_fact AS ans 
          ON cards.fact_id=ans.fact_id AND ans.key='a'
        JOIN data_for_fact AS ques 
          ON cards.fact_id=ques.fact_id AND ques.key='q'
      WHERE cards.fact_view_id='2::2'
    

    Or you could use CASE expressions:

    SELECT card_id, 
           CASE cards.fact_view_id WHEN '2::1' THEN ques.value ELSE  ans.value END AS q, 
           CASE cards.fact_view_id WHEN '2::1' THEN  ans.value ELSE ques.value END AS a 
      FROM cards
        JOIN data_for_fact AS ques 
          ON cards.fact_id=ques.fact_id AND ques.key='q'
        JOIN data_for_fact AS ans 
          ON cards.fact_id=ans.fact_id AND ans.key='a'
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a schema that essentially looks like this: CREATE TABLE `data` ( `id`
I have a database schema like that DataMapper.setup :default, sqlite://#{Dir.pwd}/image.db class Image include DataMapper::Resource
I have a schema design that looks like this: Table: User Row Column Family
I have a database schema that is similar to the following: | User |
I know that I should have schema of a table before calling NewRow method
I have two tables in my database schema that represent an entity having a
I have a Sql Database (which I have no control over the schema) that
Considering that I have a Schema named SBST I want to find all empty
I have xsd schema file which I can't change. Here is an excerpt that
I have a schema called application. Is there a way that, rather than using

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.