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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T12:45:11+00:00 2026-05-23T12:45:11+00:00

I have 3 tables in a m2m relationship in a mysql database as follows:

  • 0

I have 3 tables in a m2m relationship in a mysql database as follows:

tbltest (test_id, testdescription)
tblprofile (profile_id, profiledescription)
tbltestprofile(testprofile_id,test_id,profile_id)

I need to display test_id and description from the test table where I have no matching records in tbltestprofile and where the profile_id = x

I’ve tried various combinations using NOT IN but without the desired results. Can anyone assist?

  • 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-23T12:45:12+00:00Added an answer on May 23, 2026 at 12:45 pm
    SELECT test_id
         , testdescription
    FROM tbltest AS t
    WHERE NOT EXISTS
          ( SELECT *
            FROM tbltestprofile tp 
            WHERE t.test_id = tp.test_id
              AND tp.profile_id = X
          )
    


    Sidenote. It would help if you kept table (and field) names simple and not add the tbl prefix, like test, profile, testprofile. A simple 3-table join you have probably used:

    SELECT tbltest.test_id
         , tbltest.testdescription
         , tblprofile.profile_id
         , tblprofile.profiledescription
    FROM tbltest
      JOIN tbltestprofile
        ON tbltest.test_id = tbltestprofile.test_id
      JOIN tblprofile
        ON tblprofile.profile_id = tbltestprofile.profile_id
    ORDER BY tblprofile.profiledescription
    

    makes me rather dizzy. Wouldn’t it be better like this? Even without aliases:

    SELECT test.id              AS test_id
         , test.description     AS test
         , profile.id           AS profile_id
         , profile.description  AS profile
    FROM test
      JOIN testprofile
        ON test.id = testprofile.test_id
      JOIN profile
        ON profile.id = testprofile.profile_id
    ORDER BY profile.description
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have tables in a MySQL database like this... CREATE TABLE `someUserTable` ( userId
In the database we have tables called Sites, Organisations, Person, Department have the same
I have tables in Mysql 5 db with names prefixed with a dollar sign
I have tables Users, Widgets and Layouts. Users have many-to-many relationship with Widgets via
i have tables driver, cars and trailers they are all in relationship. and main
I have tables in a local database I've built in Visual Studio 2008 that
In my database I have tables that define types for example Table: Publication Types
When I have tables in my database that have PK/FK relationships (int) and when
I have tables A, B and C in database. I have to put the
We have tables Site and Content in our database. Each site is operated by

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.