这是SQL查询:
SELECT
`cards.ID` AS ID,
`cards.SetName` AS SetName,
`variations.varCARDID` AS varCARDID,
`variations.varID` AS varID,
`collections.have` AS have,
`variations.varTTP` AS varTTP,
`variations.varPOP` AS varPOP,
`collections.userID` AS userID,
`collections.relID` AS relID
FROM
`cards` AS C,
`variations` AS V,
`collections` AS Co
JOIN
C
ON
`cards.ID` = `variations.varCARDID`
JOIN
V
ON
`variations.varID` = `collections.relID`
WHERE
`cards.SetName` = 'Ancient Origins' AND `collections.userID` = 2
这是表结构
表卡:表变体:
表集:
我想要实现的目标:
特定用户为特定集合拥有的卡片及其变体列表。
我已经根据这里的大约6篇文章(stackoverflow)更改了我的原始代码,并得到了相同的结果。
提前感谢您的帮助。
修改
以下是我尝试修复之前的原始代码:
SELECT
cards.ID AS ID,
cards.SetName AS SetName,
variations.varCARDID AS varCARDID,
variations.varID AS varID,
collections.have AS have,
variations.varTTP AS varTTP,
variations.varPOP AS varPOP,
collections.userID AS userID,
collections.relID AS relID
FROM
cards,
variations,
collections
JOIN
cards
ON
cards.ID = variations.varCARDID
JOIN
variations
ON
variations.varID = collections.relID
WHERE
cards.SetName = 'Ancient Origins' AND collections.userID = 2
答案 0 :(得分:0)
选择...... 来自卡片c 在v.Varcardid = c.id上加入变体v 加入co.id = v.varid上的集合co 哪里......
答案 1 :(得分:0)
好的,我选择了这个作为解决方案:
$sql_new="SELECT `cards`.`ID`, `collections`.`relID`, `variations`.`varCARDID`, `variations`.`varID`, `variations`.`varName`, `variations`.`varTTP` AS TTP, `variations`.`varPOP` AS POP, `collections`.`have` AS have, `collections`.`userID` From `cards`, `variations`, `collections` WHERE `cards`.`SetName` = '" .$row["SetName"] . "' AND `variations`.`varCARDID` = `cards`.`ID` AND `collections`.`relID` = `variations`.`varCARDID` AND `collections`.`have`>0 AND `collections`.`userID` = " . $_SESSION["id"];