Skip to content
Advertisement

Where to place limit clause?

I am trying to place a limit clause on the database query to only show the first 4 results.

The current code I am working with is

The problem that I am having is I found a way to limit only 4 results by placing LIMIT 4 after the order query, and it shows the first 4 parent categories, but it also removes the sub categories from the list.

So I want to take this

and see this

and when placing ‘LIMIT 4’ in the query it only shows this

How do I keep the subcategories with the parent categories? Aparently calling only the first 4 does not call the categories under it

Advertisement

Answer

The query is doing exactly what you’re asking it to do – “LIMIT” means you get just 4 records back, ordered by categoryID.

To get what you want, you have to rephrase the query – I haven’t go SQL installed on this laptop, so it’s hard to test, but something like this:

User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement