Solved

How to write multiple conditions in SQL ?

Posted on 2013-05-21
4
428 Views
Last Modified: 2013-05-21
Hi,

I'm joining more than 5 tables but each table need to check with one master table.
Example:

Table1 attributes : id, name,phoneno
table2 , table3,table,4,table5.

where table1.id = table2.id and table1.id=table3.id and table1.id=table4.id

Is there any alternative for this condition ?
0
Comment
Question by:Rose_Taylor
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
4 Comments
 
LVL 38

Accepted Solution

by:
Gerwin Jansen, EE MVE earned 500 total points
ID: 39185848
>> Is there any alternative for this condition ?

What do you mean by 'alternative'? If you have to check 4 tables against 1 table that contains an ID field, you have to check, either by using AND or using a JOIN statement or by using an IN clause.

There are probably some nicer ways to write it down but if you want to match ID's of the 4 tables to one master table, you just have to do that.
0
 
LVL 23

Expert Comment

by:nemws1
ID: 39185873
What's "more than 5" - 10? 200?  If 10, manually doing it would be fastest.  If 200, think about creating your SQL statement with a program (maybe even *with* SQL - aka Dynamically Generated SQL)
0
 

Author Closing Comment

by:Rose_Taylor
ID: 39186003
Thanks for clarification
0
 
LVL 48

Expert Comment

by:PortletPaul
ID: 39186155
where table1.id = table2.id and table1.id=table3.id and table1.id=table4.id
>>Is there any alternative for this condition ?
YES
use ANSI join syntax (strongly recommend you adopt this syntax!)

select table1.id, table1.name, table1.phoneno
from table1
inner join table2 on table1.id = table2.id
inner join table3 on table1.id = table3.id
inner join table4 on table1.id = table4.id
inner join table5. on table1.id = table5.id
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article describes how to use the timestamp of existing data in a database to allow Tableau to calculate the prior work day instead of relying on case statements or if statements to calculate the days of the week.
When it comes to protecting Oracle Database servers and systems, there are a ton of myths out there. Here are the most common.
This video explains at a high level with the mandatory Oracle Memory processes are as well as touching on some of the more common optional ones.
This video shows how to recover a database from a user managed backup

739 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question