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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T05:34:53+00:00 2026-05-23T05:34:53+00:00

I have a mysql table with 2 columns and a set of values called

  • 0

I have a mysql table with 2 columns and a set of values called MAIN.
table1:

col1, int(11)
col2, int(11)

Set of values:
MAIN: 1,3,4

col1 and col2 contain random integers between 1 and 10 for 1000 rows. Then, any rows where col1 and col1 contain the SAME integer are removed.

I’m trying to pull those rows from table1 where:
col1 contains values from MAIN and col2 does not.
AND
col2 contains values from MAIN and col1 does not.

in invented pseudo code I have:

mysql_query("SELECT col1,col2 
             FROM table1 
             WHERE (col1 contains values from MAIN and col2 does not) 
             OR (col2 contains values from MAIN and col1 does not) ");

Any ideas on what the correct syntax is for this?

P.S. The set of values starts as a PHP array.

  • 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-23T05:34:53+00:00Added an answer on May 23, 2026 at 5:34 am

    Perhaps you’re looking for the XOR logical operator?

    SELECT
      col1,
      col2
    FROM
      table1
    WHERE
      ( col1 IN ( 1, 3, 4 ) XOR col2 IN ( 1, 3, 4 ) );
    

    Small example of how XOR works:

    SELECT true XOR true; -- false
    SELECT true XOR false; -- true
    SELECT false XOR true; -- true
    SELECT false XOR false; -- false
    

    That’s pretty much your whole ( col1 in ( MAIN ) and col2 not in main ) OR ( col1 not in ( MAIN ) and col2 in ( main ) ), but written more succinct 😉

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

Sidebar

Related Questions

I have a legacy MySQL table called lnk_lists_addresses with columns list_id and address_id .
I have a MySQL table with many numeric columns (some INT, some FLOAT). I
I have a table set up on a mysql database called access with three
I have a MySQL table with a number of columns, including one called 'Name'.
My (MySQL) tables have columns with currency values set as Decimal(10,2) with decimals separated
I have a DATE datatype mysql column in a table. I want to set
I have a MySQL InnoDB table with 238 columns. 56 of them are TEXT
I have multiple columns in a mySQL table. Three of the columns are named
if i have a table which has columns with fixed lenght, Will mySQL count
Say I have an MSSQL table with two columns: an int ID column that's

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.