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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T19:30:24+00:00 2026-05-25T19:30:24+00:00

Please forgive my ignorance here. SQL is decidedly one of the biggest gaps in

  • 0

Please forgive my ignorance here. SQL is decidedly one of the biggest “gaps” in my education that I’m working on correcting, come October. Here’s the scenario:

I have two tables in a DB that I need to access certain data from. One is users, and the other is conversation_log. The basic structure is outlined below:

users:

  • id (INT)
  • name (TXT)

conversation_log

  • userid (INT) // same value as id in users – actually the only field in this table I want to check
  • input (TXT)
  • response (TXT)

(note that I’m only listing the structure for the fields that are {or could be} relevant to the current challenge)

What I want to do is return a list of names from the users table that have at least one record in the conversation_log table. Currently, I’m doing this with two separate SQL statements, with the one that checks for records in conversation_log being called hundreds, if not thousands of times, once for each userid, just to see if records exist for that id.

Currently, the two SQL statements are as follows:

select id from users where 1; (gets the list of userid values for the next query)

select id from conversation_log where userid = $userId limit 1; (checks for existing records)

Right now I have 4,000+ users listed in the users table. I’m sure that you can imagine just how long this method takes. I know there’s an easier, more efficient way to do this, but being self-taught, this is something that I have yet to learn. Any help would be greatly appreciated.

  • 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-25T19:30:25+00:00Added an answer on May 25, 2026 at 7:30 pm

    You have to do what is called a ‘Join’. This, um, joins the rows of two tables together based on values they have in common.

    See if this makes sense to you:

    SELECT DISTINCT users.name
    FROM users JOIN conversation_log ON users.id = converation_log.userid
    

    Now JOIN by itself is an “inner join”, which means that it will only return rows that both tables have in common. In other words, if a specific conversation_log.userid doesn’t exist, it won’t return any part of the row, user or conversation log, for that userid.

    Also, +1 for having a clearly worded question : )

    EDIT: I added a “DISTINCT”, which means to filter out all of the duplicates. If a user appeared in more than one conversation_log row, and you didn’t have DISTINCT, you would get the user’s name more than once. This is because JOIN does a cartesian product, or does every possible combination of rows from each table that match your JOIN ON criteria.

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

Sidebar

Related Questions

Please forgive my ignorance and poor SQL programming skills but I am normally a
I'm not a Rails developer (currently) so please forgive my ignorance on this. One
XML/XSL newbie here, so please forgive my ignorance. This is the xml input given
Please forgive my ignorance, but I wasn't able to find an answer elsewhere. I
This is probably a very simple question so please forgive my ignorance, but can
Please forgive me if this is an obvious one. I have an unknown amount
Veterans please forgive me for asking silly question. I understand that a class having
I am a brand new programming student, so please forgive my ignorance. My assignment
All, Please forgive my ignorance of C#/.NET, I am absolutely new to both (mostly
please forgive my windows ignorance, Is there an application which can show me which

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.