@@ -10,20 +10,20 @@ In SQL, we use `ORDER BY` to sort query results and `LIMIT` to restrict the numb
10
10
- ` { field: -1 } ` → ** Descending order** (Z → A, largest to smallest)
11
11
- You can sort by multiple fields, just like SQL.
12
12
13
- ## ** Limiting Results **
13
+ ## ** Limiting results **
14
14
15
15
- ` .limit(n) ` restricts the number of documents returned.
16
16
- Used together with ` .sort() ` , it helps fetch the ** top N** results.
17
17
18
18
---
19
19
20
- ### 1: Top 5 Books with the Highest Inventory
20
+ ### 1: Top 5 books with the highest inventory
21
21
22
22
``` js
23
23
db .books .find ().sort ({ totalInventory: - 1 }).limit (5 );
24
24
```
25
25
26
- ** Equivalent SQL Query :**
26
+ ** Equivalent SQL query :**
27
27
28
28
``` sql
29
29
SELECT * FROM books ORDER BY totalInventory DESC LIMIT 5 ;
@@ -33,7 +33,7 @@ This fetches the **5 books with the highest stock**.
33
33
34
34
---
35
35
36
- ### 2: Get the title of top 10 Fiction Books by highest page count
36
+ ### 2: Get the title of top 10 fiction books by highest page count
37
37
38
38
``` js
39
39
db .books
@@ -44,11 +44,11 @@ db.books
44
44
45
45
:::info
46
46
47
- Along with the title, we fetched pages as well to ensure that we are getting the right results.
47
+ Along with the title, we fetched pages, as well, to ensure that we are getting the right results.
48
48
49
49
:::
50
50
51
- ** Equivalent SQL Query :**
51
+ ** Equivalent SQL query :**
52
52
53
53
``` sql
54
54
SELECT title, pages FROM books WHERE genres= ' Fiction' ORDER BY pages DESC LIMIT 10 ;
0 commit comments