Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

How to write multiple conditions in SQL ?

Posted on 2013-05-21
4
Medium Priority
?
432 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 38

Accepted Solution

by:
Gerwin Jansen, EE MVE earned 1500 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

Prepare for your VMware VCP6-DCV exam.

Josh Coen and Jason Langer have prepared the latest edition of VCP study guide. Both authors have been working in the IT field for more than a decade, and both hold VMware certifications. This 163-page guide covers all 10 of the exam blueprint sections.

Question has a verified solution.

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

I'm trying, I really am. But I've seen so many wrong approaches involving date(time) boundaries I despair about my inability to explain it. I've seen quite a few recently that define a non-leap year as 364 days, or 366 days and the list goes on. …
An alternative to the "For XML" way of pivoting and concatenating result sets into strings, and an easy introduction to "common table expressions" (CTEs). Being someone who is always looking for alternatives to "work your data", I came across this …
This video shows how to copy a database user from one database to another user DBMS_METADATA.  It also shows how to copy a user's permissions and discusses password hash differences between Oracle 10g and 11g.
This video shows syntax for various backup options while discussing how the different basic backup types work.  It explains how to take full backups, incremental level 0 backups, incremental level 1 backups in both differential and cumulative mode a…
Suggested Courses

963 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