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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T03:20:30+00:00 2026-06-13T03:20:30+00:00

I would like to do as follows: Select * from table1 a inner join

  • 0

I would like to do as follows:

Select * from
table1  a
inner join table2 b

on

a.id = b.id

if (some condition is met) //  Now it gets interesting!

begin

and a.name = b.name

end

Obviously, this doesn’t work.

How can this best be accomplished?

Thanks Stackers!

  • 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-13T03:20:31+00:00Added an answer on June 13, 2026 at 3:20 am

    I would use something like this:

    SELECT * FROM table1 a
    JOIN table2 b ON (a.id = b.id)
    WHERE NOT ( == your condition here == ) OR a.name = b.name
    

    If you really want to put it in the join condition, you could do something like this:

    SELECT * FROM table1 a
    JOIN table2 b ON (a.id = b.id AND (NOT ( == your condition here == ) OR a.name = b.name))
    

    but I think the first form is more clear.

    EDIT: as @James Curtis noted in the comments:

    it is important to note that the option to put the condition in the
    WHERE clause is only valid for an INNER JOIN, for an outer join you
    may eliminate rows.

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

Sidebar

Related Questions

I have three mysql tables that I would like to extract some information from,
I have a table like follows: mysql> select * from tries; +----+--------+-----------+ | id
If I have a query/results set as follows... from t1 in table1 join t2
I would like to know what rules Entity Framework follows in regards to the
I would like to POST an entity as follows POST /example.org/MyEntity/100 Based on the
I would like to initialize an object in javascript.. My code is as follows:
I would like to do the follow redirection using htaccess: From: http://www.mywebsite.com/home/?page_id=273&mnth=8&yr=1993 To: http://www.mywebsite.com/
Would like to parse IPv4 address from exit-addresses . Format of the file: ExitNode
Greetings, I would like to include CASE Statement inside my where statement as follows:
This question follows on from MYSQL join results set wiped results during IN ()

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.