Solved

How to write multiple conditions in SQL ?

Posted on 2013-05-21
4
429 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 49

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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

When it comes to protecting Oracle Database servers and systems, there are a ton of myths out there. Here are the most common.
It is possible to export the data of a SQL Table in SSMS and generate INSERT statements. It's neatly tucked away in the generate scripts option of a database.
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, step by step, how to configure Oracle Heterogeneous Services via the Generic Gateway Agent in order to make a connection from an Oracle session and access a remote SQL Server database table.
Suggested Courses

626 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