尝试修复我自己的现有代码的错误,而不是由me.Bug与此代码是除非相应的id在第二个表中的项目,它不会显示在输出在all.In第一个表(邮件)我有多个条目,他们被过滤掉了,输出中确实显示正确的邮件总数…只是不会输出它,除非邮件在第二个表中有项目。我尝试了另一个使用diff join的查询
SELECT
id,
messageType,
sender,
mail.receiver,
subject,
body,
has_items,
money,
cod,
checked
FROM
mail
LEFT OUTER JOIN mail_items
ON id = mail_id
LEFT JOIN item_instance
ON item_guid = guid问题是..。I get error:您的SQL语法中有一个错误;请查看与您的MySQL服务器版本相对应的手册,以获得正确的语法,以便在“LIMIT 1”附近使用。
我怎么做才能使邮件表和mail_items表在正确地从第三个表中获得项目guid的同时加入,并输出邮件表条目,即使在mail_items表中没有该邮件的项目。
//==========================$_GET and SECURE=================================
$start = (isset($_GET['start'])) ? $sqlc->quote_smart($_GET['start']) : 0;
if (is_numeric($start));
else
$start = 0;
$order_by = (isset($_GET['order_by'])) ? $sqlc->quote_smart($_GET['order_by']) : 'id';
if (preg_match('/^[_[:lower:]]{1,12}$/', $order_by));
else
$order_by = 'id';
$dir = (isset($_GET['dir'])) ? $sqlc->quote_smart($_GET['dir']) : 1;
if (preg_match('/^[01]{1}$/', $dir));
else
$dir = 1;
$order_dir = ($dir) ? 'ASC' : 'DESC';
$dir = ($dir) ? 0 : 1;
//==========================$_GET and SECURE end=============================
$query = $sql->query("SELECT a.id, a.messageType, a.sender, a.receiver, a.subject, a.body, a.has_items, a.money, a.cod, a.checked, b.item_guid, c.itemEntry
FROM mail a INNER JOIN mail_items b ON a.id = b.mail_id LEFT JOIN item_instance c ON b.item_guid = c.guid ORDER BY $order_by $order_dir LIMIT $start, $itemperpage");
$total_found = $sql->num_rows($query);
$this_page = $sql->num_rows($query);
$query_1 = $sql->query("SELECT count(*) FROM `mail`");
$all_record = $sql->result($query_1,0);发布于 2012-09-09 13:59:29
尝试如下所示:
SELECT
/*
The columns that you want to select
*/
FROM
mail a
LEFT OUTER JOIN mail_items b ON a.id = b.mail_id
LEFT JOIN item_instance c ON b.item_guid = c.guid请注意,当您尝试选择列时,请确保将正确的表别名附加到列名。在这里,表mail、mail_items和item_instance分别使用a、b和c作为其别名。
如果您使用上面的查询为表保留相同的别名,则需要对您的代码执行以下修改:
$order_by = (isset($_GET['order_by'])) ? $sqlc->quote_smart($_GET['order_by']) : 'id';
if (preg_match('/^[_[:lower:]]{1,12}$/', $order_by));
else
$order_by = 'a.id';发布于 2012-09-09 14:02:09
我不是SQL专家,但我认为
FROM mail a INNER JOIN mail_items b 别名分配需要AS关键字:
FROM mail AS a INNER JOIN mail_items AS b 发布于 2012-09-09 14:11:17
尝试此类型,从table1 as T1 join table2 as T2 on T.id=T2.id join table3 as T3 on T2.id=T3.id中选择*
https://stackoverflow.com/questions/12336853
复制相似问题