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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T07:43:45+00:00 2026-05-14T07:43:45+00:00

My google search skills have failed me, and I am not a database expert

  • 0

My google search skills have failed me, and I am not a database expert by any means! I have a very simple database schema that looks like this:

database schema http://bit.ly/adeUVL

properties_id in the CANDY table is a foreign key to id in the EXPENSIVE_PROPERTIES table. The properties_id is only set if the candy is expensive. If it is expensive, then the corresponding values in the EXPENSIVE_PROPERTIES table will get filled in.

When I want to get a list of the candies, I basically want to do this:

  • request all of the properties in the CANDY table, like name and color
  • optionally get the expensive properties if the properties_id value is not null

In the past, I have done two queries, but this is silly since I should be able to create a view that aggregates all of the properties into one table, and just leaves the other fields blank if there isn’t a corresponding id in the EXPENSIVE_PROPERTIES table.

Can anyone tell me how to create this view in SQLite? I assume it’s possible, but couldn’t figure it out from the docs:

alt text

The IF NOT EXISTS elements don’t seem to have anything to do with the existence of a particular field value.

UPDATE

The question has been answered, but one thing I find weird is that in some cases I see duplicate entries. I’m using SQLite Administrator, and when I execute the CREATE VIEW statement and look in the results tab, I get unique entries. If I just do a SELECT statement, I get duplicate rows. If I create the view, and then do a SELECT * FROM myview; I also see duplicate rows. Can anyone shed some light on this? Should I create a new question?

UPDATE #2

Never mind, I found my mistake — I had two tables after FROM, which causes the duplication.

  • 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-14T07:43:45+00:00Added an answer on May 14, 2026 at 7:43 am

    You can use LEFT OUTER JOIN to retrieve data from another table that may not have data for some rows in your primary table.

    create view vCandy as
    select c.id, c.name, c.color, c.properties,
     ep.chocolate, ep.gold_foil
    from Candy c
    left outer join Expensive_Properties ep on c.properties_id = ep.id
    

    The IF NOT EXISTS does not refer to dealing with data that does not exist. Rather, it means it will create the view if it does not exist already. This is to prevent errors when running the statement more than once.

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

Sidebar

Related Questions

I have found a XML file through google search that will help me for
Google search did not yield any ideas or solutions neither did SO search.( One
Does Google search provide sorting option on metadata. I have requirement that suggest to
I have created a Google Search function, however I would like to leave the
I infer from Google search results that strings.h (from here ) is for UNIX
A simple google search for: CGRect + C or CGRect in C brings back
what I have: a google search form (displayed on all pages) a wordpress page
According to Google search: since MySQL does not support full outer join, it could
Any Google search on PHP ical just brings up phpicalendar and how to parse
After some Google search, I did not find anything fill my need. I want

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.