Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
Author |
Topic |
kandy
Starting Member
15 Posts |
Posted - 2006-10-04 : 14:38:45
|
What is the equivalent for a either 'or' query in sql.ie.select * from table3 which satisfies <either condition1 frm table1> <or condition 2 from table 2> |
|
tkizer
Almighty SQL Goddess
38200 Posts |
Posted - 2006-10-04 : 14:51:59
|
Did you try using OR?SELECT * FROM SomeTableWHERE Column1 = 1 OR Column2 = 1Tara Kizer |
 |
|
snSQL
Master Smack Fu Yak Hacker
1837 Posts |
Posted - 2006-10-04 : 18:05:05
|
Looks like you're using three tables so you have to join them firstSELECT t1.* FROM table1 t1LEFT OUTER JOIN table2 t2 ON t2.someid = t1.someidLEFT OUTER JOIN table3 t3 ON t3.someid = t1.someidWHERE t2.column = something OR t3.column = something I used OUTER joins because the fact you want either or suggest that there won't always be a row in table2 or table3 to match to the row in table1. |
 |
|
kandy
Starting Member
15 Posts |
Posted - 2006-10-05 : 14:01:08
|
i tried using tht query..doesnt seem to work..i needselect column1,column2 from table 1 t1 and t3 mus be joined on column at2 and t3 mus be joined on column b in t4where column='' from t2 or column ='' from t1 |
 |
|
snSQL
Master Smack Fu Yak Hacker
1837 Posts |
Posted - 2006-10-05 : 15:15:15
|
You'll need to post a better example of what you need. Suddenly you say "in t4", I have no idea what that means, you didn't even have a t4 in your original question.Post sample data from the three/four tables and explain what "in t4" means. |
 |
|
kandy
Starting Member
15 Posts |
Posted - 2006-10-05 : 16:22:40
|
i have 4 tables.orders(order_num ,order_date)part(part_num,description)customer(customer_name,customer_num)order_line(part_num,order_num)I need to list the order number and order datefrom orders table for each order that was either placed by Johnson's Department Store(i.e customer_name in customer table)or that contains an order line for a Gas Range(gas range is the value for description in the part table)customer and orders table join on customer_numorders and order_line table join on order_numpart table and order_line table join on part_num |
 |
|
snSQL
Master Smack Fu Yak Hacker
1837 Posts |
Posted - 2006-10-05 : 17:39:39
|
[code]SELECT o.order_num, o.order_dateFROM orders oLEFT OUTER JOIN customers c ON c.customer_num = o.customer_numLEFT OUTER JOIN order_line ol ON ol.order_num = o.order_numLEFT OUTER JOIN part p ON p.partnum = ol.part_numWHERE c.customer_name = 'Johnson''s Department Store' OR p.description = 'Gas Range'[/code] |
 |
|
|
|
|