[英]how to get all rows except with specific values
Hello is there a way to only get the survey_name
that the organisation has not used yet?您好,有没有办法只获取组织尚未使用的
survey_name
?
`survey table`
+-----------+-------------+
| survey_id | survey_name |
+-----------+-------------+
| 1 | name1 |
| 2 | name2 |
| 3 | name3 |
| 4 | name4 |
| 5 | name5 |
+-----------+-------------+
`link table`
+---------+-------------+-----------------+
| link_id | survey_link | organisation_id |
+---------+-------------+-----------------+
| 1 | 1(survey_id)| 1 |
| 2 | 2 | 1 |
| 3 | 2 | 2 |
| 3 | 3 | 2 |
| 3 | 6 | 2 |
+---------+-------------+-----------------+
In this database structure you would see this for each organisation:在此数据库结构中,您会看到每个组织的信息:
available surveys organisation1:可用的调查组织1:
available surveys organisation1:可用的调查组织1:
I have tried using WHERE NOT (survey_id= $row['survey_id'])
我试过使用
WHERE NOT (survey_id= $row['survey_id'])
//get all survey's that are in use
$sqlCheckLink = "SELECT `survey_id` FROM `link_info` WHERE `organisation_id`=".$_SESSION['organisation_id']."";
$resultCheck = mysqli_query($conn, $sqlCheckLink);
if ($resultCheck ->num_rows > 0) {
while ($id = $resultCheck -> fetch_assoc()) {
//show all surveys that are available
$sqlGetSurveys = "SELECT * FROM `survey_info` WHERE NOT (survey_id = ".$id['survey_id'].")";
$resultAllSurveys = mysqli_query($conn, $sqlGetSurveys);
if ($resultAllSurveys ->num_rows > 0) {
while ($row = $resultAllSurveys-> fetch_assoc()) {
//echo content
}
}
}
}
from here But it does not seem to work... With this method I get also the surveys that are in use.从这里但它似乎不起作用......使用这种方法我也得到了正在使用的调查。
If someone could help it would be really appreciated!如果有人可以提供帮助,将不胜感激!
Just using LEFT JOIN:只需使用左连接:
SELECT t.survey_name
FROM survey_table as t
LEFT JOIN link_table AS l ON l.survey_link = t.survey_id
WHERE l.link_id IS NULL
Not tested, but you can get the idea.未经测试,但您可以了解这个想法。 I hope this help you.
我希望这对你有帮助。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.