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

  • Home
  • SEARCH
  • 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 9273661
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T16:09:59+00:00 2026-06-18T16:09:59+00:00

First, please note that I have little experience with SQL (in this case sqlite3)

  • 0

First, please note that I have little experience with SQL (in this case sqlite3) and so even the title of this question may be ill-phrased.

Suppose that I have a table of notes (n), and a table of keywords for those notes (k), and finally a table associating one or more keywords to each note (nk). What I’d like to do is to find notes that each contain two (or more) keywords.

To be a bit more specific, below (sqlite3) is how I’ve set up the database.

CREATE TABLE n(nid integer primary key autoincrement, content);
CREATE TABLE k(kid integer primary key autoincrement, content);
CREATE TABLE nk(nkid integer primary key autoincrement, nid, kid);
INSERT INTO n(content) VALUES ("note 1");
INSERT INTO n(content) VALUES ("note 2");
INSERT INTO k(content) VALUES ("keyword 1");
INSERT INTO k(content) VALUES ("keyword 2");
INSERT INTO nk(nid, kid) VALUES (1, 1);
INSERT INTO nk(nid, kid) VALUES (1, 2);
INSERT INTO nk(nid, kid) VALUES (2, 1);

With this, I can get notes tagged with a keyword ID of 1 with

select * from n LEFT JOIN nk ON nk.nid = n.nid WHERE nk.kid=1;

and my question is how I can get notes with keyword IDs 1 and 2. I’ve done some searching on the web, but I’m afraid that my knowledge is insufficient to think of good searching terms. I hope someone on this site can help and — importantly — I apologize if this is a silly question.

  • 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-18T16:10:01+00:00Added an answer on June 18, 2026 at 4:10 pm

    To improve on @GordonLinoff’s answer:

    select * from n where nid IN 
     (select nid
      from (select * from nk where kid in (1,2)) s
      group by nid
      having count(distinct s.kid) = 2)
    

    This will get those records that have kid matching 1 and 2 even if other kid values might be present (3,4,etc). sqlfiddle here.

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

Sidebar

Related Questions

I have code like that 010200345 i want split every first three digit please
I am enhancing a tool. Please note that this tool will be linked to
First of all, i'm a Graphic designer so please ignore if this programming question
Say I have HTML that looks like this: <p> May 4 - <a href=http://auburn.craigslist.org/web/2996976345.html>residual
Please note that although it sounds similar, this is not the common how to
I have a simple script named example : #!/bin/sh echo $'${1}' Please note that
First, please be gentle, I know very little about DB design. I am working
First time Stack Overflow poster. Please bear with me! :) I have a set
Please take a look at this screenshot first: I would like to move the
Please visit this link Click on first Image. Now is showing the Modal page

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.