Solved

How to write multiple conditions in SQL ?

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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
make null the repeated levels 2 31
SYS password changed. Now can't log in as SYS 27 30
Loading flat file data in tables 2 41
Need return values from a stored procedure 8 21
'Between' is such a common word we rarely think about it but in SQL it has a very specific definition we should be aware of. While most database vendors will have their own unique phrases to describe it (see references at end) the concept in common …
This post first appeared at Oracleinaction  (http://oracleinaction.com/undo-and-redo-in-oracle/)by Anju Garg (Myself). I  will demonstrate that undo for DML’s is stored both in undo tablespace and online redo logs. Then, we will analyze the reaso…
Via a live example show how to connect to RMAN, make basic configuration settings changes and then take a backup of a demo database
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…

828 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