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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T06:37:59+00:00 2026-06-08T06:37:59+00:00

I have a parent table A that have 2 foreign keys (from tables B

  • 0

I have a parent table A that have 2 foreign keys (from tables B and C), but it can have just one foreign key at a time. Example:

SELECT a.evi, a.time, a.date, 
       a.number, a.descr, a.x, 
       a.y, a.z,  a.FK_tableB, a.FK_tableC, 
       b.brand, b.type, 
       b.color, b.model, c.name, c.lastname, 
  FROM tableA a, 
       tableB b, 
       tableC c  
 WHERE (PK_tableA = 100 AND PK_tableB = FK_tableB)      
    OR (PK_tableA = 100 AND PK_tableC = FK_tableC)

(This is not working, obviusly)

How do I return data when just one of the where clauses is true.

  • 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-06-08T06:38:00+00:00Added an answer on June 8, 2026 at 6:38 am

    It appears you want to do a “Exclusive OR” (XOR) on your query.

    Since SQL doesn’t have XOR, you could try something like:

    create table a
    ( a_id int, b_id int, c_id int);
    
    create table b
    ( b_id int);
    
    create table c
    ( c_id int);
    
    insert into a (a_id, b_id, c_id) values (1, 1, 1);
    insert into a (a_id, b_id, c_id) values (2, NULL, 2);
    insert into a (a_id, b_id, c_id) values (3, 2, NULL);
    insert into a (a_id, b_id, c_id) values (4, NULL, NULL);
    
    insert into b (b_id) values (1);
    insert into b (b_id) values (2);
    
    insert into c (c_id) values (1);
    insert into c (c_id) values (2);
    
    SELECT a.a_id, a.b_id, a.c_id, b.b_id, c.c_id
      FROM a 
      LEFT JOIN b
        ON (a.b_id = b.b_id)
      LEFT JOIN c  
        ON (a.c_id = c.c_id)
     WHERE (   (b.b_id is NOT NULL AND c.c_id is NULL) 
            OR (c.c_id is NOT NULL AND b.b_id is NULL));
    

    See this SQLFiddle to try it out.

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

Sidebar

Related Questions

I have a simple parent/child tables. Contract is the parent table. Each contract can
I have two tables connected with one to many relationship. Parent Table is a
I have a table Parent and a table Child. Child contains a foreign-key to
I have a parent table with two foreign key references to a child table.
I have a number of child tables that have a foreign key to a
So I have a parent that defines a onmouseup event that hide/display a table.
If I have a parent table and a child table where there can be
I have two tables Loan(Parent Table) and Receipt(Child table)what i want to do is
My situation may be a bit abnormal, but I have foreign keys defined in
I have a question regarding Foreign Keys in an InnoDB Table. I have 4

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.