[{"data":1,"prerenderedAt":1069},["ShallowReactive",2],{"blog-\u002Fblog\u002Fsql-sorting-limiting-order-by":3},{"id":4,"title":5,"body":6,"description":1055,"difficulty":1056,"extension":1057,"framework":1058,"frameworkSlug":60,"meta":1059,"navigation":111,"order":85,"path":1060,"qaPath":1061,"seo":1062,"stem":1063,"subtopic":1064,"topic":1065,"topicSlug":1066,"updated":1067,"__hash__":1068},"blog\u002Fblog\u002Fsql-sorting-limiting-order-by.md","SQL ORDER BY, LIMIT & OFFSET — Sorting and Paging Results",{"type":7,"value":8,"toc":1044},"minimark",[9,14,35,51,55,208,219,223,229,305,309,315,341,356,458,462,480,592,595,702,706,712,730,734,737,848,863,867,873,1021,1025,1040],[10,11,13],"h2",{"id":12},"why-sort-and-limit-matter","Why sort and limit matter",[15,16,17,18,22,23,26,27,31,32,34],"p",{},"A ",[19,20,21],"code",{},"SELECT"," without ",[19,24,25],{},"ORDER BY"," returns rows in an ",[28,29,30],"strong",{},"undefined order"," — the\ndatabase is free to return them however it pleases, and that order can change\nbetween runs as data grows or indexes are rebuilt. Any result set shown to a\nuser, exported to a file, or compared in a test needs an explicit ",[19,33,25],{},".",[15,36,37,40,41,44,45,47,48,50],{},[19,38,39],{},"LIMIT"," (and its SQL-standard equivalent ",[19,42,43],{},"FETCH FIRST",") caps how many rows come\nback. Together, ",[19,46,25],{}," + ",[19,49,39],{}," are the building blocks of ranked lists,\ndashboards, and paginated APIs.",[10,52,54],{"id":53},"order-by-basics","ORDER BY basics",[56,57,62],"pre",{"className":58,"code":59,"language":60,"meta":61,"style":61},"language-sql shiki shiki-themes github-light github-dark","-- Newest orders first\nSELECT id, customer_id, total_amount, created_at\nFROM orders\nORDER BY created_at DESC;\n\n-- Alphabetically by last name, then first name\nSELECT id, first_name, last_name\nFROM customers\nORDER BY last_name ASC, first_name ASC;\n\n-- Cheapest in-stock products first\nSELECT product_name, unit_price, stock_quantity\nFROM products\nWHERE stock_quantity > 0\nORDER BY unit_price ASC;\n","sql","",[19,63,64,73,83,92,106,113,119,127,135,153,158,164,172,180,196],{"__ignoreMap":61},[65,66,69],"span",{"class":67,"line":68},"line",1,[65,70,72],{"class":71},"sJ8bj","-- Newest orders first\n",[65,74,76,79],{"class":67,"line":75},2,[65,77,21],{"class":78},"szBVR",[65,80,82],{"class":81},"sVt8B"," id, customer_id, total_amount, created_at\n",[65,84,86,89],{"class":67,"line":85},3,[65,87,88],{"class":78},"FROM",[65,90,91],{"class":81}," orders\n",[65,93,95,97,100,103],{"class":67,"line":94},4,[65,96,25],{"class":78},[65,98,99],{"class":81}," created_at ",[65,101,102],{"class":78},"DESC",[65,104,105],{"class":81},";\n",[65,107,109],{"class":67,"line":108},5,[65,110,112],{"emptyLinePlaceholder":111},true,"\n",[65,114,116],{"class":67,"line":115},6,[65,117,118],{"class":71},"-- Alphabetically by last name, then first name\n",[65,120,122,124],{"class":67,"line":121},7,[65,123,21],{"class":78},[65,125,126],{"class":81}," id, first_name, last_name\n",[65,128,130,132],{"class":67,"line":129},8,[65,131,88],{"class":78},[65,133,134],{"class":81}," customers\n",[65,136,138,140,143,146,149,151],{"class":67,"line":137},9,[65,139,25],{"class":78},[65,141,142],{"class":81}," last_name ",[65,144,145],{"class":78},"ASC",[65,147,148],{"class":81},", first_name ",[65,150,145],{"class":78},[65,152,105],{"class":81},[65,154,156],{"class":67,"line":155},10,[65,157,112],{"emptyLinePlaceholder":111},[65,159,161],{"class":67,"line":160},11,[65,162,163],{"class":71},"-- Cheapest in-stock products first\n",[65,165,167,169],{"class":67,"line":166},12,[65,168,21],{"class":78},[65,170,171],{"class":81}," product_name, unit_price, stock_quantity\n",[65,173,175,177],{"class":67,"line":174},13,[65,176,88],{"class":78},[65,178,179],{"class":81}," products\n",[65,181,183,186,189,192],{"class":67,"line":182},14,[65,184,185],{"class":78},"WHERE",[65,187,188],{"class":81}," stock_quantity ",[65,190,191],{"class":78},">",[65,193,195],{"class":194},"sj4cs"," 0\n",[65,197,199,201,204,206],{"class":67,"line":198},15,[65,200,25],{"class":78},[65,202,203],{"class":81}," unit_price ",[65,205,145],{"class":78},[65,207,105],{"class":81},[15,209,210,212,213,215,216,218],{},[19,211,145],{}," (ascending, A→Z, 0→9) is the default and can be omitted. Columns not in\n",[19,214,21],{}," can still appear in ",[19,217,25],{}," — the sort happens before projection.",[10,220,222],{"id":221},"multi-column-sorts","Multi-column sorts",[15,224,225,226,228],{},"Each column in ",[19,227,25],{}," gets its own direction. The database sorts by the\nfirst column, then breaks ties using the second, and so on.",[56,230,232],{"className":58,"code":231,"language":60,"meta":61,"style":61},"-- High-value orders on top; within same total, most recent first\nSELECT id, customer_id, total_amount, created_at\nFROM orders\nORDER BY total_amount DESC, created_at DESC;\n\n-- Product grid: category ascending, then price ascending within category\nSELECT product_name, category, unit_price\nFROM products\nORDER BY category ASC, unit_price ASC;\n",[19,233,234,239,245,251,267,271,276,283,289],{"__ignoreMap":61},[65,235,236],{"class":67,"line":68},[65,237,238],{"class":71},"-- High-value orders on top; within same total, most recent first\n",[65,240,241,243],{"class":67,"line":75},[65,242,21],{"class":78},[65,244,82],{"class":81},[65,246,247,249],{"class":67,"line":85},[65,248,88],{"class":78},[65,250,91],{"class":81},[65,252,253,255,258,260,263,265],{"class":67,"line":94},[65,254,25],{"class":78},[65,256,257],{"class":81}," total_amount ",[65,259,102],{"class":78},[65,261,262],{"class":81},", created_at ",[65,264,102],{"class":78},[65,266,105],{"class":81},[65,268,269],{"class":67,"line":108},[65,270,112],{"emptyLinePlaceholder":111},[65,272,273],{"class":67,"line":115},[65,274,275],{"class":71},"-- Product grid: category ascending, then price ascending within category\n",[65,277,278,280],{"class":67,"line":121},[65,279,21],{"class":78},[65,281,282],{"class":81}," product_name, category, unit_price\n",[65,284,285,287],{"class":67,"line":129},[65,286,88],{"class":78},[65,288,179],{"class":81},[65,290,291,293,296,298,301,303],{"class":67,"line":137},[65,292,25],{"class":78},[65,294,295],{"class":81}," category ",[65,297,145],{"class":78},[65,299,300],{"class":81},", unit_price ",[65,302,145],{"class":78},[65,304,105],{"class":81},[10,306,308],{"id":307},"null-ordering","NULL ordering",[15,310,311,314],{},[19,312,313],{},"NULL"," is neither greater than nor less than any value. Where NULLs sort\ndepends on the database:",[316,317,318,333],"ul",{},[319,320,321,324,325,328,329,332],"li",{},[28,322,323],{},"Postgres \u002F Oracle",": NULLs sort ",[28,326,327],{},"last"," in ASC, ",[28,330,331],{},"first"," in DESC.",[319,334,335,324,338,340],{},[28,336,337],{},"MySQL \u002F SQL Server",[28,339,331],{}," in ASC.",[15,342,343,344,347,348,351,352,355],{},"Use explicit ",[19,345,346],{},"NULLS FIRST"," \u002F ",[19,349,350],{},"NULLS LAST"," (Postgres, Oracle) or a ",[19,353,354],{},"CASE","\nworkaround (MySQL, SQL Server) to control this:",[56,357,359],{"className":58,"code":358,"language":60,"meta":61,"style":61},"-- Postgres: tasks with no due date sink to the bottom\nSELECT id, title, due_date\nFROM tasks\nORDER BY due_date ASC NULLS LAST;\n\n-- MySQL equivalent (CASE pushes NULLs to position 1 → last)\nSELECT id, title, due_date\nFROM tasks\nORDER BY CASE WHEN due_date IS NULL THEN 1 ELSE 0 END, due_date ASC;\n",[19,360,361,366,373,380,397,401,406,412,418],{"__ignoreMap":61},[65,362,363],{"class":67,"line":68},[65,364,365],{"class":71},"-- Postgres: tasks with no due date sink to the bottom\n",[65,367,368,370],{"class":67,"line":75},[65,369,21],{"class":78},[65,371,372],{"class":81}," id, title, due_date\n",[65,374,375,377],{"class":67,"line":85},[65,376,88],{"class":78},[65,378,379],{"class":81}," tasks\n",[65,381,382,384,387,389,392,395],{"class":67,"line":94},[65,383,25],{"class":78},[65,385,386],{"class":81}," due_date ",[65,388,145],{"class":78},[65,390,391],{"class":78}," NULLS",[65,393,394],{"class":78}," LAST",[65,396,105],{"class":81},[65,398,399],{"class":67,"line":108},[65,400,112],{"emptyLinePlaceholder":111},[65,402,403],{"class":67,"line":115},[65,404,405],{"class":71},"-- MySQL equivalent (CASE pushes NULLs to position 1 → last)\n",[65,407,408,410],{"class":67,"line":121},[65,409,21],{"class":78},[65,411,372],{"class":81},[65,413,414,416],{"class":67,"line":129},[65,415,88],{"class":78},[65,417,379],{"class":81},[65,419,420,422,425,428,430,433,436,439,442,445,448,451,454,456],{"class":67,"line":137},[65,421,25],{"class":78},[65,423,424],{"class":78}," CASE",[65,426,427],{"class":78}," WHEN",[65,429,386],{"class":81},[65,431,432],{"class":78},"IS",[65,434,435],{"class":78}," NULL",[65,437,438],{"class":78}," THEN",[65,440,441],{"class":194}," 1",[65,443,444],{"class":78}," ELSE",[65,446,447],{"class":194}," 0",[65,449,450],{"class":78}," END",[65,452,453],{"class":81},", due_date ",[65,455,145],{"class":78},[65,457,105],{"class":81},[10,459,461],{"id":460},"limit-and-offset","LIMIT and OFFSET",[15,463,464,467,468,471,472,475,476,479],{},[19,465,466],{},"LIMIT n"," returns at most ",[19,469,470],{},"n"," rows. ",[19,473,474],{},"OFFSET k"," skips the first ",[19,477,478],{},"k"," rows.\nTogether they paginate a result set.",[56,481,483],{"className":58,"code":482,"language":60,"meta":61,"style":61},"-- Top 10 best-selling products\nSELECT product_id, SUM(quantity) AS units_sold\nFROM order_items\nGROUP BY product_id\nORDER BY units_sold DESC\nLIMIT 10;\n\n-- Page 3 of a customer list (page size = 20)\nSELECT id, email, created_at\nFROM customers\nORDER BY created_at DESC\nLIMIT 20 OFFSET 40;  -- skip pages 1 and 2\n",[19,484,485,490,509,516,524,534,543,547,552,559,565,573],{"__ignoreMap":61},[65,486,487],{"class":67,"line":68},[65,488,489],{"class":71},"-- Top 10 best-selling products\n",[65,491,492,494,497,500,503,506],{"class":67,"line":75},[65,493,21],{"class":78},[65,495,496],{"class":81}," product_id, ",[65,498,499],{"class":194},"SUM",[65,501,502],{"class":81},"(quantity) ",[65,504,505],{"class":78},"AS",[65,507,508],{"class":81}," units_sold\n",[65,510,511,513],{"class":67,"line":85},[65,512,88],{"class":78},[65,514,515],{"class":81}," order_items\n",[65,517,518,521],{"class":67,"line":94},[65,519,520],{"class":78},"GROUP BY",[65,522,523],{"class":81}," product_id\n",[65,525,526,528,531],{"class":67,"line":108},[65,527,25],{"class":78},[65,529,530],{"class":81}," units_sold ",[65,532,533],{"class":78},"DESC\n",[65,535,536,538,541],{"class":67,"line":115},[65,537,39],{"class":78},[65,539,540],{"class":194}," 10",[65,542,105],{"class":81},[65,544,545],{"class":67,"line":121},[65,546,112],{"emptyLinePlaceholder":111},[65,548,549],{"class":67,"line":129},[65,550,551],{"class":71},"-- Page 3 of a customer list (page size = 20)\n",[65,553,554,556],{"class":67,"line":137},[65,555,21],{"class":78},[65,557,558],{"class":81}," id, email, created_at\n",[65,560,561,563],{"class":67,"line":155},[65,562,88],{"class":78},[65,564,134],{"class":81},[65,566,567,569,571],{"class":67,"line":160},[65,568,25],{"class":78},[65,570,99],{"class":81},[65,572,533],{"class":78},[65,574,575,577,580,583,586,589],{"class":67,"line":166},[65,576,39],{"class":78},[65,578,579],{"class":194}," 20",[65,581,582],{"class":81}," OFFSET ",[65,584,585],{"class":194},"40",[65,587,588],{"class":81},";  ",[65,590,591],{"class":71},"-- skip pages 1 and 2\n",[15,593,594],{},"SQL Server \u002F Oracle syntax:",[56,596,598],{"className":58,"code":597,"language":60,"meta":61,"style":61},"-- SQL Server\nSELECT TOP 10 * FROM orders ORDER BY total_amount DESC;\n\n-- SQL:2008 standard (Postgres, SQL Server 2012+, Oracle 12c+)\nSELECT * FROM orders ORDER BY total_amount DESC\nFETCH FIRST 10 ROWS ONLY;\n\n-- With offset\nOFFSET 40 ROWS FETCH NEXT 20 ROWS ONLY;\n",[19,599,600,605,631,635,640,656,672,676,681],{"__ignoreMap":61},[65,601,602],{"class":67,"line":68},[65,603,604],{"class":71},"-- SQL Server\n",[65,606,607,609,612,614,617,620,623,625,627,629],{"class":67,"line":75},[65,608,21],{"class":78},[65,610,611],{"class":78}," TOP",[65,613,540],{"class":194},[65,615,616],{"class":78}," *",[65,618,619],{"class":78}," FROM",[65,621,622],{"class":81}," orders ",[65,624,25],{"class":78},[65,626,257],{"class":81},[65,628,102],{"class":78},[65,630,105],{"class":81},[65,632,633],{"class":67,"line":85},[65,634,112],{"emptyLinePlaceholder":111},[65,636,637],{"class":67,"line":94},[65,638,639],{"class":71},"-- SQL:2008 standard (Postgres, SQL Server 2012+, Oracle 12c+)\n",[65,641,642,644,646,648,650,652,654],{"class":67,"line":108},[65,643,21],{"class":78},[65,645,616],{"class":78},[65,647,619],{"class":78},[65,649,622],{"class":81},[65,651,25],{"class":78},[65,653,257],{"class":81},[65,655,533],{"class":78},[65,657,658,661,664,666,669],{"class":67,"line":115},[65,659,660],{"class":78},"FETCH",[65,662,663],{"class":78}," FIRST",[65,665,540],{"class":194},[65,667,668],{"class":78}," ROWS",[65,670,671],{"class":81}," ONLY;\n",[65,673,674],{"class":67,"line":121},[65,675,112],{"emptyLinePlaceholder":111},[65,677,678],{"class":67,"line":129},[65,679,680],{"class":71},"-- With offset\n",[65,682,683,686,688,690,693,696,698,700],{"class":67,"line":137},[65,684,685],{"class":81},"OFFSET ",[65,687,585],{"class":194},[65,689,668],{"class":78},[65,691,692],{"class":78}," FETCH",[65,694,695],{"class":78}," NEXT",[65,697,579],{"class":194},[65,699,668],{"class":78},[65,701,671],{"class":81},[10,703,705],{"id":704},"the-offset-pagination-problem","The OFFSET pagination problem",[15,707,708,711],{},[19,709,710],{},"OFFSET"," is convenient but has two problems at scale:",[713,714,715,724],"ol",{},[319,716,717,720,721,723],{},[28,718,719],{},"Performance",": the database reads and discards the first ",[19,722,478],{}," rows on every\nrequest. Page 500 of 20 items means discarding 9 980 rows.",[319,725,726,729],{},[28,727,728],{},"Drift",": if a row is inserted or deleted between page requests, items shift\n— the user sees a duplicate or skips a row.",[10,731,733],{"id":732},"keyset-cursor-pagination-the-fix","Keyset (cursor) pagination — the fix",[15,735,736],{},"Instead of skipping rows by count, remember the last seen value and filter from\nthere. This is O(log n) with an index instead of O(n).",[56,738,740],{"className":58,"code":739,"language":60,"meta":61,"style":61},"-- First page: 20 newest orders\nSELECT id, created_at, customer_id, total_amount\nFROM orders\nORDER BY created_at DESC, id DESC\nLIMIT 20;\n\n-- Next page: pass the last row's (created_at, id) as the cursor\nSELECT id, created_at, customer_id, total_amount\nFROM orders\nWHERE (created_at, id) \u003C ('2026-06-15 10:23:00', 5831)\nORDER BY created_at DESC, id DESC\nLIMIT 20;\n",[19,741,742,747,754,760,773,781,785,790,796,802,828,840],{"__ignoreMap":61},[65,743,744],{"class":67,"line":68},[65,745,746],{"class":71},"-- First page: 20 newest orders\n",[65,748,749,751],{"class":67,"line":75},[65,750,21],{"class":78},[65,752,753],{"class":81}," id, created_at, customer_id, total_amount\n",[65,755,756,758],{"class":67,"line":85},[65,757,88],{"class":78},[65,759,91],{"class":81},[65,761,762,764,766,768,771],{"class":67,"line":94},[65,763,25],{"class":78},[65,765,99],{"class":81},[65,767,102],{"class":78},[65,769,770],{"class":81},", id ",[65,772,533],{"class":78},[65,774,775,777,779],{"class":67,"line":108},[65,776,39],{"class":78},[65,778,579],{"class":194},[65,780,105],{"class":81},[65,782,783],{"class":67,"line":115},[65,784,112],{"emptyLinePlaceholder":111},[65,786,787],{"class":67,"line":121},[65,788,789],{"class":71},"-- Next page: pass the last row's (created_at, id) as the cursor\n",[65,791,792,794],{"class":67,"line":129},[65,793,21],{"class":78},[65,795,753],{"class":81},[65,797,798,800],{"class":67,"line":137},[65,799,88],{"class":78},[65,801,91],{"class":81},[65,803,804,806,809,812,815,819,822,825],{"class":67,"line":155},[65,805,185],{"class":78},[65,807,808],{"class":81}," (created_at, id) ",[65,810,811],{"class":78},"\u003C",[65,813,814],{"class":81}," (",[65,816,818],{"class":817},"sZZnC","'2026-06-15 10:23:00'",[65,820,821],{"class":81},", ",[65,823,824],{"class":194},"5831",[65,826,827],{"class":81},")\n",[65,829,830,832,834,836,838],{"class":67,"line":160},[65,831,25],{"class":78},[65,833,99],{"class":81},[65,835,102],{"class":78},[65,837,770],{"class":81},[65,839,533],{"class":78},[65,841,842,844,846],{"class":67,"line":166},[65,843,39],{"class":78},[65,845,579],{"class":194},[65,847,105],{"class":81},[15,849,850,851,854,855,858,859,862],{},"The ",[19,852,853],{},"id"," tiebreaker ensures stable ordering when two rows share the same\n",[19,856,857],{},"created_at",". The index on ",[19,860,861],{},"(created_at DESC, id DESC)"," makes this fast at any\npage depth.",[10,864,866],{"id":865},"order-by-with-expressions-and-case","ORDER BY with expressions and CASE",[15,868,869,870,872],{},"You can sort by an expression or computed value directly in ",[19,871,25],{},":",[56,874,876],{"className":58,"code":875,"language":60,"meta":61,"style":61},"-- Sort by absolute value of profit margin (closest to zero first)\nSELECT product_name, (revenue - cost) AS profit\nFROM products\nORDER BY ABS(revenue - cost) ASC;\n\n-- Custom priority: 'urgent' tickets first, then by created_at\nSELECT id, title, priority, created_at\nFROM support_tickets\nORDER BY CASE priority\n           WHEN 'urgent'   THEN 1\n           WHEN 'high'     THEN 2\n           WHEN 'medium'   THEN 3\n           ELSE 4\n         END,\n         created_at ASC;\n",[19,877,878,883,901,907,925,929,934,941,948,957,971,984,996,1004,1012],{"__ignoreMap":61},[65,879,880],{"class":67,"line":68},[65,881,882],{"class":71},"-- Sort by absolute value of profit margin (closest to zero first)\n",[65,884,885,887,890,893,896,898],{"class":67,"line":75},[65,886,21],{"class":78},[65,888,889],{"class":81}," product_name, (revenue ",[65,891,892],{"class":78},"-",[65,894,895],{"class":81}," cost) ",[65,897,505],{"class":78},[65,899,900],{"class":81}," profit\n",[65,902,903,905],{"class":67,"line":85},[65,904,88],{"class":78},[65,906,179],{"class":81},[65,908,909,911,914,917,919,921,923],{"class":67,"line":94},[65,910,25],{"class":78},[65,912,913],{"class":194}," ABS",[65,915,916],{"class":81},"(revenue ",[65,918,892],{"class":78},[65,920,895],{"class":81},[65,922,145],{"class":78},[65,924,105],{"class":81},[65,926,927],{"class":67,"line":108},[65,928,112],{"emptyLinePlaceholder":111},[65,930,931],{"class":67,"line":115},[65,932,933],{"class":71},"-- Custom priority: 'urgent' tickets first, then by created_at\n",[65,935,936,938],{"class":67,"line":121},[65,937,21],{"class":78},[65,939,940],{"class":81}," id, title, priority, created_at\n",[65,942,943,945],{"class":67,"line":129},[65,944,88],{"class":78},[65,946,947],{"class":81}," support_tickets\n",[65,949,950,952,954],{"class":67,"line":137},[65,951,25],{"class":78},[65,953,424],{"class":78},[65,955,956],{"class":81}," priority\n",[65,958,959,962,965,968],{"class":67,"line":155},[65,960,961],{"class":78},"           WHEN",[65,963,964],{"class":817}," 'urgent'",[65,966,967],{"class":78},"   THEN",[65,969,970],{"class":194}," 1\n",[65,972,973,975,978,981],{"class":67,"line":160},[65,974,961],{"class":78},[65,976,977],{"class":817}," 'high'",[65,979,980],{"class":78},"     THEN",[65,982,983],{"class":194}," 2\n",[65,985,986,988,991,993],{"class":67,"line":166},[65,987,961],{"class":78},[65,989,990],{"class":817}," 'medium'",[65,992,967],{"class":78},[65,994,995],{"class":194}," 3\n",[65,997,998,1001],{"class":67,"line":174},[65,999,1000],{"class":78},"           ELSE",[65,1002,1003],{"class":194}," 4\n",[65,1005,1006,1009],{"class":67,"line":182},[65,1007,1008],{"class":78},"         END",[65,1010,1011],{"class":81},",\n",[65,1013,1014,1017,1019],{"class":67,"line":198},[65,1015,1016],{"class":81},"         created_at ",[65,1018,145],{"class":78},[65,1020,105],{"class":81},[10,1022,1024],{"id":1023},"recap","Recap",[15,1026,1027,1028,1030,1031,1033,1034,1036,1037,1039],{},"Always pair ",[19,1029,25],{}," with ",[19,1032,39],{}," — an unsorted limit is meaningless. Use\n",[19,1035,350],{}," (or the CASE workaround) when nullable sort columns would push\nNULLs to the wrong end. Replace ",[19,1038,710],{},"-based pagination with keyset\npagination for any list that grows beyond a few hundred rows — it stays fast\nregardless of page depth and avoids row-drift bugs.",[1041,1042,1043],"style",{},"html pre.shiki code .sJ8bj, html code.shiki .sJ8bj{--shiki-default:#6A737D;--shiki-dark:#6A737D}html pre.shiki code .szBVR, html code.shiki .szBVR{--shiki-default:#D73A49;--shiki-dark:#F97583}html pre.shiki code .sVt8B, html code.shiki .sVt8B{--shiki-default:#24292E;--shiki-dark:#E1E4E8}html pre.shiki code .sj4cs, html code.shiki .sj4cs{--shiki-default:#005CC5;--shiki-dark:#79B8FF}html .default .shiki span {color: var(--shiki-default);background: var(--shiki-default-bg);font-style: var(--shiki-default-font-style);font-weight: var(--shiki-default-font-weight);text-decoration: var(--shiki-default-text-decoration);}html .shiki span {color: var(--shiki-default);background: var(--shiki-default-bg);font-style: var(--shiki-default-font-style);font-weight: var(--shiki-default-font-weight);text-decoration: var(--shiki-default-text-decoration);}html .dark .shiki span {color: var(--shiki-dark);background: var(--shiki-dark-bg);font-style: var(--shiki-dark-font-style);font-weight: var(--shiki-dark-font-weight);text-decoration: var(--shiki-dark-text-decoration);}html.dark .shiki span {color: var(--shiki-dark);background: var(--shiki-dark-bg);font-style: var(--shiki-dark-font-style);font-weight: var(--shiki-dark-font-weight);text-decoration: var(--shiki-dark-text-decoration);}html pre.shiki code .sZZnC, html code.shiki .sZZnC{--shiki-default:#032F62;--shiki-dark:#9ECBFF}",{"title":61,"searchDepth":75,"depth":75,"links":1045},[1046,1047,1048,1049,1050,1051,1052,1053,1054],{"id":12,"depth":75,"text":13},{"id":53,"depth":75,"text":54},{"id":221,"depth":75,"text":222},{"id":307,"depth":75,"text":308},{"id":460,"depth":75,"text":461},{"id":704,"depth":75,"text":705},{"id":732,"depth":75,"text":733},{"id":865,"depth":75,"text":866},{"id":1023,"depth":75,"text":1024},"How SQL ORDER BY, LIMIT, OFFSET, and FETCH work — multi-column sorts, NULL ordering, stable pagination, and the keyset alternative to OFFSET.","easy","md","SQL",{},"\u002Fblog\u002Fsql-sorting-limiting-order-by","\u002Fsql\u002Fbasics\u002Fsorting-limiting",{"title":5,"description":1055},"blog\u002Fsql-sorting-limiting-order-by","Sorting & Limiting","Query Basics","basics","2026-06-20","_C5-D6NWIx1MZ99gO1Z1S_L7Yb3wfdaV5PhvEYkcByI",1782244088760]