Solved

How to write multiple conditions in SQL ?

Posted on 2013-05-21
4
425 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
4 Comments
 
LVL 37

Accepted Solution

by:
Gerwin Jansen 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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Suggested Solutions

Have you ever had to make fundamental changes to a table in Oracle, but haven't been able to get any downtime?  I'm talking things like: * Dropping columns * Shrinking allocated space * Removing chained blocks and restoring the PCTFREE * Re-or…
If you find yourself in this situation “I have used SELECT DISTINCT but I’m getting duplicates” then I'm sorry to say you are using the wrong SQL technique as it only does one thing which is: produces whole rows that are unique. If the results you a…
This video shows setup options and the basic steps and syntax for duplicating (cloning) a database from one instance to another. Examples are given for duplicating to the same machine and to different machines
This video shows how to configure and send email from and Oracle database using both UTL_SMTP and UTL_MAIL, as well as comparing UTL_SMTP to a manual SMTP conversation with a mail server.

760 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

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now