Colleen78 Posted April 3, 2007 Share Posted April 3, 2007 Thanks for any help with this. My client has a cart for which I've made a custom homepage. We use this query to display the 3 newest items on the homepage: $query = 'SELECT * FROM `tbl_item` GROUP BY `item_id` ORDER BY `item_id` DESC LIMIT 3'; Now, my client has several categories which he does not want the items of to be displayed on the homepage. In the database the column is "category_id" which is within the same table as in the query shown above. How would I exclude several categories from being displayed via the query above? Thanks. Quote Link to comment https://forums.phpfreaks.com/topic/45475-solved-how-would-i-exclude-certain-categories-within-my-query/ Share on other sites More sharing options...
Colleen78 Posted April 3, 2007 Author Share Posted April 3, 2007 I found this code will exclude 1 ID, but I need to exclude multiple ID's, not sure how. $query = 'SELECT * FROM `tbl_item` WHERE NOT (category_id = "138") GROUP BY `item_id` ORDER BY `item_id` DESC LIMIT 3'; Ideally, I would like to exclude a whole parent ID, so I just have to put one ID, but the parent_id is in another table, the "categories" table, not the items table. Quote Link to comment https://forums.phpfreaks.com/topic/45475-solved-how-would-i-exclude-certain-categories-within-my-query/#findComment-220801 Share on other sites More sharing options...
fenway Posted April 4, 2007 Share Posted April 4, 2007 Well, you can use IN clauses, but it makes more sense to LEFT JOIN in the other table . Quote Link to comment https://forums.phpfreaks.com/topic/45475-solved-how-would-i-exclude-certain-categories-within-my-query/#findComment-221223 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.