在while循环中只显示未插入另一个表中的记录


show in a while loop only the records not inserted in another table

我有两个表,categorias和precios

在类别中保存所有类别

在精确的情况下只有几个

过一段时间我该如何展示在悬崖上丢失的记录?

$query = $mysqli->query("select * from categorias"); //all data stored
while ($resultados = $query->fetch_array()) {  //here we show
 $m =$resultados['subcat']; //the subcats..

为什么我只显示在precios表中没有插入的类别?

我试过了,但不起作用:

$query = $mysqli->query("select * from categorias where subcat != '$pi'");

$pi是在precios 中插入的类别

如果SUBCAT是PRECIOS上的FOREGIN KEY:

SELECT * FROM CATEGORIAS WHERE SUBCAT NOT IN 
(SELECT ID FROM PRECIOS) 

试试这个:

SELECT * FROM categorias WHERE
NOT EXISTS(SELECT * FROM precious WHERE cat=subcat)