Home > SQL Development > [Query - General] Select multiple tables..

[Query - General] Select multiple tables..




PHP Code:





 details "SELECT  weeklyreport.Supp_name, weeklyreport.PartNumber, weeklyreport.Description, cbom_filtered.comCode ,cbom_filtered.UploadTime, supplier_feedback2.DateNow from weeklyreport, cbom_filtered, fa, supplier_feedback2 where ProjectName='" &pro"'" 









error on the ProjectName is ambiguous...



how do i select the value from those 4 tables based on the projectName??

    
Guest


Generally when selecting from multiple tables you should specify the relationship between the tables. How they will be joined.



ex:


sql Code:
















Original
- sql Code


  1. SELECT a.CustomerName, a.CustomerAddress, b.OrderTotal
  2. FROM Customers AS a
  3. INNER JOIN Orders AS b ON a.OrderID = b.OrderID






However, to just answer your question, you will need to say table1.ProjectName = <value> and table2.ProjectName = <value> and table3.ProjectName = <value> and table4.ProjectName = <value>

Was this answer helpful ? Yes No   
Guest



PHP Code:





 details "select W.Supp_name, W.PartNumber, W.description, S.DateNow, F.status, F.FileName from weeklyreport as W inner join(supplier_feedback2 as S inner join fa as F on (S.ProjectName = F.ProjectName)on( W.ProjectName = S.ProjectName) where S.DateNow between '"&from_date&"' and '"&to_date&"'"







If pro <> "All " Then

    details 
details " AND W.ProjectName='" &pro"'"

End If



detailsdetails " ORDER BY PartNumber"



Set rsdetails conn.Execute(details









i did this.. but still got error on




PHP Code:





 MySQL][ODBC 3.51 Driver][mysqld-4.1.22-community-nt]You have an error in your SQL syntaxcheck the manual that corresponds to your MySQL server version for the right syntax to use near 'on( W.ProjectName = S.ProjectName) where S.DateNow between '' and '' AND W.Proje' at line 1 






Was this answer helpful ? Yes No   
Guest


Quote:
Originally Posted by lyealain

PHP Code:





 details "select W.Supp_name, W.PartNumber, W.description, S.DateNow, F.status, F.FileName from weeklyreport as W inner join(supplier_feedback2 as S inner join fa as F on (S.ProjectName = F.ProjectName)on( W.ProjectName = S.ProjectName) where S.DateNow between '"&from_date&"' and '"&to_date&"'"







If pro <> "All " Then

    details 
details " AND W.ProjectName='" &pro"'"

End If



detailsdetails " ORDER BY PartNumber"



Set rsdetails conn.Execute(details









i did this.. but still got error on




PHP Code:





 MySQL][ODBC 3.51 Driver][mysqld-4.1.22-community-nt]You have an error in your SQL syntaxcheck the manual that corresponds to your MySQL server version for the right syntax to use near 'on( W.ProjectName = S.ProjectName) where S.DateNow between '' and '' AND W.Proje' at line 1 









Join syntax still doesn't look quite right.



Try something more like:




Code:



select W.Supp_name, W.PartNumber, W.description
, S.DateNow, F.status, F.FileName
from weeklyreport as W
inner join supplier_feedback2 as S
on W.ProjectName = S.ProjectName
inner join fa as F
on S.ProjectName = F.ProjectName
where S.DateNow between '"&from_date&"' and '"&to_date&"'"






Each "inner join" statement needs one table. Immediately after the inner join, you have to use the "on" statement to tell how the join operates. You then add additional joins and on statements one at a time.



Been a few years since I used MySQL, but I don't think you have to use parenthesis on your join conditions. I know you don't have to in MSSQL.

Was this answer helpful ? Yes No   
Guest
 
 
Home - About Infoqu - Contact - Privacy Statement - Link to Infoqu - Bookmark Infoqu

Copyright 2007-2008 by Infoqu. All rights reserved