[英]Compare one field from one table to several fields in anther table in mysql via php
I have this line 我有这条线
$sql_events = mysql_query("SELECT team FROM weekpicks WHERE whatweek='$totalnoOfWeek'-1 and team in ( SELECT team1 FROM weekslosers WHERE whatweek='$totalnoOfWeek'-1 ) ORDER BY 'username' asc ")
It works, but I need it to also check team2, team3 and so on. 它可以工作,但我还需要检查一下team2,team3等。 I thought I could do something like the following, but it does not work.
我以为可以做下面的事情,但是没有用。 it appears to stop at team1
似乎停在team1
$sql_events = mysql_query("SELECT team FROM weekpicks WHERE whatweek='$totalnoOfWeek'-1 and team in ( SELECT team1 FROM weekslosers WHERE whatweek='$totalnoOfWeek'-1 ) or ( SELECT team2 FROM weekslosers WHERE whatweek='$totalnoOfWeek'-1 ) ORDER BY 'username' asc ")
Or should this be done a different way? 还是应该以其他方式完成?
What I am looking to do is take the team from the table weekpicks and compare it to the teams in table weekslosers and the weekslosers table could have up to 8 losing teams so if your team is one of the 8, I need it to be listed. 我要做的是从桌上的周票中拿出球队,并将其与桌上的周输者中的球队进行比较,而周输者表中最多可以有8支输球队伍,所以如果您的球队是8支队伍之一,我需要将其列出。
SELECT team
FROM weekpicks
INNER JOIN weekslosers ON weekpicks.whatweek = weekslosers.whatweek
WHERE weekpicks.whatweek = (whatever) AND team IN (weekslosers.team1, weekslosers.team2)
Also, you should look into transitioning away from mysql_* and towards mysqli or PDO. 另外,您应该考虑从mysql_ *过渡到mysqli或PDO。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.