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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T23:36:07+00:00 2026-05-15T23:36:07+00:00

I have 2 tables items and item_relations items has 4 columns row_id(primary key), story_id,

  • 0

I have 2 tables items and item_relations

items has 4 columns row_id(primary key), story_id, field1 and field2

item_relation stores the relation between each rows in items table it has 2 columns parent_story_id and child_story_id. Both columns store story_id’s of rows from items.

A parent item can have many child items and a Child can have 1 or more parent items. but a child item cannot have its own child items.

Now I want to SELECT rows from items for which items.story_id is not present in item_relation.child_story_id

How do I go about doing this?

  • 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-15T23:36:08+00:00Added an answer on May 15, 2026 at 11:36 pm

    I want to SELECT rows from items for which items.story_id is not present in item_relation.child_story_id

    You could use NOT IN, NOT EXISTS or LEFT JOIN/WHERE … IS NULL.

    An example with NOT IN:

    SELECT *
    FROM items
    WHERE items.story_id NOT IN (
        SELECT child_story_id FROM item_relation
    )
    

    An example with LEFT JOIN/WHERE … IS NULL:

    SELECT items.*
    FROM items
    LEFT JOIN item_relation
    ON items.story_id = item_relation.child_story_id
    WHERE item_relation.child_story_id IS NULL
    

    An example with NOT EXISTS:

    SELECT *
    FROM items
    WHERE NOT EXISTS (
        SELECT NULL
        FROM item_relation
        WHERE item_relation.child_story_id = items.story_id
    )
    

    The article NOT IN vs. NOT EXISTS vs. LEFT JOIN / IS NULL: MySQL by Quassnoi explains the differences between these techniques and compares their performance. The summary:

    That’s why the best way to search for missing values in MySQL is using a LEFT JOIN / IS NULL or NOT IN rather than NOT EXISTS.

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

Sidebar

Related Questions

I have two tables: Items and Colors. They have a many to many relation.
I have the following tables items similars items_similars = pivot table items->similars has a
I have three tables filters (id, name) items(item_id, name) items_filters(item_id, filter_id, value_id) values(id, filter_id,
I have three mysql tables items =========== id title items_in_categories ============================ id item_id category_id
I have a table of items. item has id, score 1, score 2. I
i have this three tables. Table: Item Columns: ItemID, Title, Content, NoChange (Date) Table:
I have here a list of items in a table. Each item has a
I have created the following tables in SQLite3 to tag items (after reading this
I have two tables: one which contains items on a checklist (checklist_id, content), and
these are the tables I have: ------ ---------- ------- |tags| -- |tagitems| -- |items|

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.