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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T19:47:43+00:00 2026-05-18T19:47:43+00:00

I have one table and I need to check if two users, for whom

  • 0

I have one table and I need to check if two users, for whom I have the IDs (e.g. 20 and 21) share the same course, just true or false.

Table: jos_gj_users
Columns: id_user, id_group

Data Example: (20; 4)
              (20; 5)
              (20; 6)
              (21; 6)
              (21; 7)

The data above shows that user 20 and user 21 share the course 6 but how do I get this with SQL just by entering the IDs and without looping through the results with PHP?

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

    Try a self-join:

    SELECT T1.id_group
    FROM jos_gj_users T1
    JOIN jos_gj_users T2
    ON T1.id_group = T2.id_group
    WHERE T1.id_user = 20
    AND T2.id_user = 21
    

    To just get a “true or false” result you can check from the client to see if at least one row exists in the result set rather than fetching the entire results.

    Alternatively you can do it in SQL by wrapping the above query in another SELECT that uses EXISTS:

    SELECT CASE WHEN EXISTS
    (
        SELECT T1.id_group
        FROM jos_gj_users T1
        JOIN jos_gj_users T2
        ON T1.id_group = T2.id_group
        WHERE T1.id_user = 20
        AND T2.id_user = 21
    ) THEN 1 ELSE 0 END AS result
    

    This query returns either 0 (false) or 1 (true).

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

Sidebar

Related Questions

I have one table TABLE_EXAM . i need to update the value of specific
I have one table TABLE_QUESTION. I need to fetch record by passing exam_id and
I have one table TABLE_SUBJECT which contain a number of subjects. I need to
I have a one table question_table and one ImageButton ( Back ). I need
i have day, month, year, value columns in one table, here i need to
I need to copy a table from one server to another.for that I have
I have two tables in database: comments table users table | u_id | text
I need to check (from the same table) if there is an association between
I have two table a) tblresign and b) tblemp tblresign has one foreign key
I have two SQLite (also MySQL could be fine) databases with same table structures

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.