我有一个问题是在仓库表中选择所有并从他们的表中获取客户和用户的名称,这些名称用于从仓库表中获取这些名称,/ p>
数据库结构:
table 1: warehouse
table 2: customer (City, FirstName, LastName)
table 3: user (FirstName, LastName)
$result = mysql_query("SELECT customer.City, customer.FirstName AS customerFName, customer.LastName AS customerLName, user.FirstName AS clientFName, user.LastName AS clientLName, warehouse.*".
"FROM warehouse".
"INNER JOIN customer, user".
"ON warehouse.CustomerID = customer.CustomerID AND warehouse.UserID = user.UserID") or trigger_error(mysql_error());
通知:您的SQL语法中有错误;查看与MySQL服务器版本对应的手册,以便在仓库附近使用正确的语法.CustomerID = customer.CustomerID AND warehouse.UserID = user.UserID'
答案 0 :(得分:0)
像这样更改查询。
$result = mysql_query("SELECT customer.City, customer.FirstName AS customerFName, customer.LastName AS customerLName, user.FirstName AS clientFName, user.LastName AS clientLName, warehouse.* ".
"FROM warehouse".
" INNER JOIN customer".
" ON warehouse.CustomerID = customer.CustomerID".
" INNER JOIN user ON warehouse.UserID = user.UserID") or trigger_error(mysql_error());
答案 1 :(得分:0)
试试这个:
SELECT c.City, c.FirstName AS customerFName, c.LastName AS customerLName,
u.FirstName AS clientFName, u.LastName AS clientLName,
w.*
FROM warehouse w
INNER JOIN customer c ON w.CustomerID = c.CustomerID
INNER JOIN user u ON w.UserID = u.UserID;
答案 2 :(得分:0)
首先,如果你只是在执行它之前打印出字符串,那么可以保存所有动态构建的SQL问题的97%(a)。
在这种情况下,由于您重新连接字符串的方式,您在单个单词之间找不到空格。
修复 后,您应该意识到inner join
一次只能处理一个表。我认为您正在寻找的是:
inner join customer on warehouse.CustomerID = customer.CustomerID
inner join user on warehouse.UserID = user.UserID
(a)图从空中拔出。实际值可能会有所不同。