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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T05:27:11+00:00 2026-05-29T05:27:11+00:00

I’m having a problem with mysql that you might be able to help. I

  • 0

I’m having a problem with mysql that you might be able to help. I have 2 tables with the following structure, and a couple of sample rows

TABLE 1
-------
LISTID     NAME        10_OTHER_COLUMNS
---------------------------------------
1          List1
2          List2
3          List3

TABLE 2
-------
LISTID      LISTTYPE(ENUM, 4 options)
------------------------------------------------
1           type1
1           type2
2           type3
3           type1
3           type2
3           type3

The relation is one to many from TABLE 1 to TABLE 2. I want to do a select on TABLE 1 where the rows are return ONLY, and ONLY IF they have exactly one match on TABLE 2. Explaining better, a list may have more than one type, if I simply do a:

SELECT t1.*
FROM table_1 t1
LEFT JOIN table_2 t2 USING (listid)
WHERE t2.listtype = 'type3'

It returns List2 and List3. I want to remove List3 from the results and only have List2. Any ideas?

  • 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-29T05:27:12+00:00Added an answer on May 29, 2026 at 5:27 am

    Ok, I THINK I got it… You are asking for ex: “type3”, an English description to clarify would be…

    Give me a list of all Tables (ie: ListID) that AT MOST have ONLY the one code I’m looking for and nothing else, not associated with any other “types”.

    select 
          t1.*
       from
          ( select
                  t2.ListID,
                  count(*) as TotalTypesForTable,
                  sum( if( t2.type = 'type3', 1, 0 )) as TypeWanted
               from
                  Table2 t2
               group by
                  t2.ListID ) PreQuery
    
          JOIN Table1 t1
             on PreQuery.ListID = t1.ListID
       where
              PreQuery.TypeWanted = 1
          AND PreQuery.TotalTypesForTable = 1
    

    FEEDBACK OPTION…

    Per your comment about a couple million records, I would adjust it this way which may also be faster overall too.

    select 
          t1.*
       from
          Table2 t2Required
    
             LEFT JOIN Table2 as t2Extra
                on t2Required.ListID = t2Extra.ListID
               AND NOT t2Extra.type = 'type3'
    
             JOIN Table1 t1
                on t2Required.ListID = t1.ListID
       where
              t2Required.type = 'type3'
          and t2Extra.ListID IS NULL
    

    I’d like to also know the performance difference on the second one. This second approach actually works based on an INTENTIONAL expected “don’t find me”, but doesn’t require a sub-select. By joining table2 to itself on same ID, but an “any other” type than the one we’re looking for, the ONLY one we want is the entry where WE DONT find in the t2Extra instance. THEN, get the table name from t1…

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

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have a French site that I want to parse, but am running into
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I ran into a problem. Wrote the following code snippet: teksti = teksti.Trim() teksti
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have just tried to save a simple *.rtf file with some websites and
I have a jquery bug and I've been looking for hours now, I can't
this is what i have right now Drawing an RSS feed into the php,
I've got a string that has curly quotes in it. I'd like to replace

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.