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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T15:54:37+00:00 2026-06-17T15:54:37+00:00

Easy question, still I can’t figure it out. I have two tables. Table items:

  • 0

Easy question, still I can’t figure it out. I have two tables.

Table items: id (INT), text (VARCHAR)
Table shared: type (VARCHAR), account (VARCHAR), id (INT)

Explanation:

  • Table items contains a list of tweets.

  • Table shared contains a list of all tweets that have been shared (sent to Twitter).

Now I need to have a query that gives me the oldest text (smallest “id”) from the items table that has not been used for a specific “type” and “account” in the shared table.

Example:

The database looks like this. There are two items in the items table and no items have been shared yet.

Table items: [[1, "First Tweet"], [2, "Second Tweet"]]
Table shared: []

Running the query will give back [1, “First Tweet”]. After that, I will insert a value in the shared table so it looks like this:

Table items: [[1, "First Tweet"], [2, "Second Tweet"]]
Table shared: [["twitter", "my-twitter-account", 1]]

Running the query again will give back [2, “Second Tweet”]. After that, I will insert a value in the shared table so it looks like this:

Table items: [[1, "First Tweet"], [2, "Second Tweet"]]
Table shared: [["twitter", "my-twitter-account", 1], ["twitter", "my-twitter-account", 2]]

I know I could do it by first pulling all “id”s from the items table, put them in an array and then check whether an “id” is in the shared table, but I think that is a horrible solution… the table will grow up to about 10,000 items max.

SOLUTION

Edit: I modified JW.’s code a bit and it works perfectly. Thanks!

My query:

SELECT a.id, a.text, MIN(a.id) ID
FROM    items a
        LEFT JOIN shared b
            ON a.id = b.id
WHERE   b.id IS NULL
  • 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-17T15:54:37+00:00Added an answer on June 17, 2026 at 3:54 pm

    try using INSERT..INTO SELECT

    INSERT INTO shared (type, account, id)
    SELECT 'twitter' type, 'my-twitter-account' account, MIN(a.id) ID
    FROM    items a
            LEFT JOIN shared b
                ON a.id = b.id
    WHERE   b.id IS NULL
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Seems like a straitforward question but I can't quite figure it out myself... I
This is probably an easy question but I can't find the answer... I have
The question is simple, please see title. I have looked everywhere and still can
I have an easy question, though I'm not sure if it's doable or not:
Hopefully an easy question. If I have an object and I want to call
Quick and easy C question: char* foo How can I test if foo hasn't
This might be an easy question but i still need some help for using
I have a question similar to the Can you override a parent UIView's alpha
How can I override Hudson build number? It sounds like an easy question, but
Sorry, I am still new using jquery so this might be an easy question.

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.