Jump to content

Help me with NOT EQUAL TO


TFG

Recommended Posts

i have two tables called category and details in my mysql database

the category table contains a column called id and has the following rows with the following values

1

2

3

4

5

6

7

8

9

10

 

and the details table contains a column called categoy and has the following rows with the following values

 

2

2

2

4

4

8

8

8

8

9

9

10

10

10

 

and now i am trying to use php to list all the values that are in category tables except the values that are in details table

as a result i want the output to be like this

1

3

6

5

7

 

please give me some idea on this

Link to comment
https://forums.phpfreaks.com/topic/101510-help-me-with-not-equal-to/
Share on other sites

To do this in php, put both tables into an array.

 

<?
$id; // The id array. eg: array(1,2,3,4,5,6,7...)
$category; // The category array eg: array(2,2,2,4,4,8,8...)

foreach($id as $n){
if(!in_array($id, $category)){
  echo $n;
}
}
?>

 

To do this in SQL,

 

SELECT category.id FROM category WHERE category.id NOT IN (SELECT details.category FROM details)

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.