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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T09:15:51+00:00 2026-05-26T09:15:51+00:00

Given the following tables: CREATE TABLE IF NOT EXISTS `rank` ( `rank_id` bigint(20) NOT

  • 0

Given the following tables:

CREATE TABLE IF NOT EXISTS `rank` ( 
`rank_id` bigint(20) NOT NULL AUTO_INCREMENT, 
`rank` int(10) NOT NULL DEFAULT '0', 
`subject_id` int(10) NOT NULL DEFAULT '0', 
`title_id` int(10) NOT NULL DEFAULT '0', 
`source_id` int(10) NOT NULL DEFAULT '0'
PRIMARY KEY (`rank_id`) 
) ENGINE=MyISAM; 

INSERT INTO `rank` (`rank_id`, `rank`, `subject_id`, `title_id`, `source_id`) VALUES 
(23, 0, 2, 1, 1), 
(22, 0, 1, 1, 1), 
(15, 0, 2, 2, 2), 
(14, 0, 2, 2, 1), 
(20, 0, 1, 3, 2), 
(18, 0, 1, 4, 2), 
(19, 0, 1, 5, 2), 
(21, 0, 1, 3, 1), 
(24, 0, 1, 6, 2); 

CREATE TABLE IF NOT EXISTS `title` ( 
`title_id` bigint(20) NOT NULL AUTO_INCREMENT, 
`title` varchar(255) DEFAULT NULL, 
`description` text, 
`pre` varchar(255) DEFAULT NULL, 
`last_modified_by` varchar(50) DEFAULT NULL, 
`last_modified` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, 
PRIMARY KEY (`title_id`) 
) ENGINE=MyISAM; 

INSERT INTO `title` (`title_id`, `title`, `last_modified`) VALUES 
(1, 'new item', ' ', '2011-10-20 19:10:48'), 
(2, 'another test', '2011-10-20 19:10:48'), 
(3, 'and yet another', '2011-10-20 19:10:48'), 
(4, 'one more', ' ', '2011-10-20 19:10:48'), 
(5, 'adding more', ' ', '2011-10-20 19:10:48'), 
(6, 'yes, another', ' ', '2011-10-20 19:10:48'), 
(7, 'well, let''s see', ' ', '2011-10-20 19:10:48'); 

My need is for a query to select all titles that are not connected to a given subject in the rank table.

I have this working via a subquery:

SELECT title_id, title FROM title
WHERE title_id NOT IN (SELECT title_id FROM rank WHERE subject_id=2)

This returns the desired list:

+----------+-----------------+ 
| title_id | title           | 
+----------+-----------------+ 
| 3        | and yet another | 
| 4        | one more        | 
| 5        | adding more     | 
| 6        | yes, another    | 
| 7        | well, let's see | 
+----------+-----------------+ 

However, it gets a little slow when a large set of data is queried.

My question is if there is a way to return this result without the use of a subquery and if this alternative is any speedier.

Thanks in advance.

  • 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-26T09:15:52+00:00Added an answer on May 26, 2026 at 9:15 am

    MySQL is usually faster with joins, though faster sub-queries are work in progress.

    SELECT t.*
    FROM title AS t
    LEFT JOIN rank AS r ON (t.title_id = r.title_id AND r.subject_id = 2)
    WHERE r.title_id IS NULL
    

    As usual, you’ll need to set up indexes on the foreign key (rank.title_id) and probably on the queried key (rank.subject_id).

    You should read the MySQL documentation on [LEFT JOIN][1] if you want more details. There’s also a nice trick with ONthat makes it different from WHERE.

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

Sidebar

Related Questions

I have the following tables: CREATE TABLE `accommodations` ( `id` int(11) unsigned NOT NULL
Given the following table structure: CREATE TABLE IF NOT EXISTS `roles` ( `id` int(11)
Given the following tables: CREATE TABLE Employees ( first_name VARCHAR(50) NOT NULL, last_name VARCHAR(50)
Given the following tables: CREATE TABLE tree ( id serial NOT NULL, name character
Given the following table: create table TreeNode ( ID int not null primary key,
Given the following table and data. create table prices (productKey int ,PriceType char(10) ,BeginDate
I have this Tags table CREATE TABLE IF NOT EXISTS `Tags` ( `id_tag` int(10)
Given a table (id, col1, col2), does it make sense to create the following
Given the following Tables: Names Id int Name varchar Properties Id int NameId varchar
I got the following weak entity (can not exist without WikiPage): CREATE TABLE WikiPageTree

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.