简体   繁体   English

sql从另一个表中清除项目

[英]sql live out items from another table

I'm putting together a league script. 我正在整理一个联赛脚本。 When someone registers for a league they choose from a list of available teams in a drop down field. 当某人注册联赛时,他们从下拉字段中的可用球队列表中进行选择。

The problem i'm having is that I'm getting this error message when there are more than one fields. 我遇到的问题是,当有多个字段时,我收到此错误消息。

"Subquery returns more than 1 row" “子查询返回多于1行”

here's the script: 这是脚本:

//List available teams
$query_chamoline = "SELECT * FROM MLB WHERE `team`<>(SELECT `team` FROM leaguemembers     WHERE `leagueid`=\"$lid\" AND `active`='Y') ORDER BY `team` ASC";
$chamoline = mysql_query($query_chamoline) or die(mysql_error());
$row_chamoline = mysql_fetch_assoc($chamoline);
$totalRows_chamoline = mysql_num_rows($chamoline);

<select id="team">
<option value="">Select Available Team</option>
<?php do { ?>   

  <?php
$tname=$row_chamoline['team'];

if($totalRows_chamoline>0)
{?>
<option value="<?php echo $tname ?>"><?php echo $tname ?></option><?php }} while     ($row_chamoline = mysql_fetch_assoc($chamoline)); ?>
</select>

I'm selecting from the total list of teams in the MLB table that doesn't match the teams picked by other members in the leaguemembers table. 我从MLB表中的球队总数列表中选择,与列表中的其他成员所挑选的球队不匹配。

change "<>" with "not in (...)" 将“ <>”更改为“不在(...)”

why? 为什么? "<>" excepts a single value (ex. 'team' <> 'xxx'), "not in" uses a set logic to handle many items (ex. 'team' not in ('aaa','bbb','ccc')) “ <>”除外一个值(例如“ team” <>“ xxx”),“不在”使用设置逻辑来处理许多项(例如,“ team”不在('aaa','bbb', 'CCC'))

尝试改用NOT IN:

$query_chamoline = "SELECT * FROM MLB WHERE `team` NOT IN(SELECT `team` FROM leaguemembers     WHERE `leagueid`=\"$lid\" AND `active`='Y') ORDER BY `team` ASC";

This change will stop the error, but not the logic error (if it exists) 此更改将停止错误,但不会停止逻辑错误(如果存在)

$query_chamoline = "SELECT * FROM MLB WHERE `team`<>(SELECT TOP 1 `team` FROM leaguemembers     WHERE `leagueid`=\"$lid\" AND `active`='Y') ORDER BY `team` ASC";

looking at his answer I expect Ass3mbler is right. 看着他的回答,我期望Ass3mbler是正确的。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM