| 
                
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 |  
                                    | aharrisStarting Member
 
 
                                        3 Posts | 
                                            
                                            |  Posted - 2009-01-20 : 10:21:13 
 |  
                                            | Hello, first post here. I have a question regarding SQL7. I have two tables, one called Orders, the other OrdItems. Only Orders contains the date field, which is OrderDate. I want to query OrdItems by using the associated date in Orders, as both tables DO contain field OrderNumber.I feel that I am close with the following query string but need some help to figure out what I'm missing.SELECT OrdItems.OrderNumber FROM Orders, OrdItems WHERE Orders.OrderDate="11/01/09' |  |  
                                    | SwePesoPatron Saint of Lost Yaks
 
 
                                    30421 Posts | 
                                        
                                          |  Posted - 2009-01-20 : 10:28:32 
 |  
                                          | What if you have two orders same day?You better JOIN the two tables with OrderID or OrderNumber instead. E 12°55'05.63"N 56°04'39.26"
 |  
                                          |  |  |  
                                    | aharrisStarting Member
 
 
                                    3 Posts | 
                                        
                                          |  Posted - 2009-01-20 : 10:42:29 
 |  
                                          | Thanks! Could you help with the syntax? I basically want to get a data set from OrdItems based on a date range, but OrdItems does not have field OrderDate, table Orders does, and they both have OrderNumber, so I was hoping to create some type of relationship, but I've never used SQL joins before.Thanks |  
                                          |  |  |  
                                    | SwePesoPatron Saint of Lost Yaks
 
 
                                    30421 Posts | 
                                        
                                          |  Posted - 2009-01-20 : 11:51:00 
 |  
                                          | SELECT o.*, oi.*FROM Orders AS oINNER JOIN OrdItems AS oi ON oi.OrderNumber = o.OrderNumberWHERE o.OrderDate = '11/01/09' E 12°55'05.63"N 56°04'39.26"
 |  
                                          |  |  |  
                                    | visakh16Very Important crosS Applying yaK Herder
 
 
                                    52326 Posts | 
                                        
                                          |  Posted - 2009-01-20 : 12:02:54 
 |  
                                          | quote:and what should output when you've multiple order items present for same orderOriginally posted by aharris
 Thanks! Could you help with the syntax? I basically want to get a data set from OrdItems based on a date range, but OrdItems does not have field OrderDate, table Orders does, and they both have OrderNumber, so I was hoping to create some type of relationship, but I've never used SQL joins before.Thanks
 
 |  
                                          |  |  |  
                                    | aharrisStarting Member
 
 
                                    3 Posts | 
                                        
                                          |  Posted - 2009-01-20 : 12:37:48 
 |  
                                          | Thanks to all that responded. Peso, that worked and I thank you for your help. |  
                                          |  |  |  
                                |  |  |  |  |  |