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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T05:09:47+00:00 2026-06-01T05:09:47+00:00

I have two tables, one that has a foreign key from the other. I

  • 0

I have two tables, one that has a foreign key from the other. I want to get all records that don’t exist in the foreign table, based on certain criteria.

Here are the tables I have:

item_setting

  • setting_id
  • category_id

item

  • item_id
  • setting_id
  • name
  • expired_dt

Here’s the query I’m using now:

SELECT 
    iset.setting_id
FROM
    item_settings iset
LEFT OUTER JOIN
    item i ON i.setting_id = iset.setting_id
WHERE
    iset.category_id = '5' AND i.setting_id is null

This query works in providing any setting_id’s that do not have a record in the item’s table within a specific category.

However, now I want to include cases where the expired_dt less than than time() (meaning it’s past expired). In otherwords, I would think to add this:

WHERE
    iset.category_id = '5' AND (i.setting_id is null OR i.expired_dt < '".time()."')

However, this doesn’t work, it returns all the records.

Any suggestions? Maybe I’m completely over complicating this…. I just want to return the setting_id’s from the item_settings table, where the expired_dt associated in the item table is expired or if it does not even exist in the item table.

Thank you!

  • 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-01T05:09:49+00:00Added an answer on June 1, 2026 at 5:09 am

    Try moving the timestamp condition into the join clause. Something like

    item_settings iset
    LEFT OUTER JOIN
        item i ON i.setting_id = iset.setting_id and i.expired_dt > time()
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Suppose I have two tables that are linked (one has a foreign key to
I have two tables, one has primary key other has it as a foreign
I want to delete multiple records at once. I have two tables, one that
So I have two tables, Table1 and Table2. Table one has an integer that
I have two tables : one table it matchs and the other is teams.
I have two tables, one called cart and one called items. Now I want
I have two tables. One (Widgets) has a list of widgets (ID, widget_name, color,
I have two tables, one is a table of forum threads. It has a
I have a table that stores two foreign keys, implementing a n:m relationship. One
So I have two tables, article and comments (which has one-to-many relationship (1 article

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.