Knowledge

Having (SQL)

Source 📝

27: 203:
To return a list of department IDs whose total sales exceeded $ 1000 on the date of January 1, 2000, along with the sum of their sales on that date:
888: 883: 577: 653: 648: 589: 164:
is taken into account at an earlier stage of a query execution, filtering the rows read from the tables. If a query contains
91: 63: 110: 70: 48: 620: 544: 44: 77: 59: 574: 37: 944: 796: 824: 287:, the following query will return the list of departments which have more than 1 employee: 387:
is convenient, but not necessary. Code equivalent to the example above, but without using
8: 867: 180:
should only apply to aggregated data, which isn't known in the initial stage of a query.
172:
is applied, filtering out the rows that don't match the specified conditions. Therefore,
84: 703: 613: 280: 168:, rows from the tables are grouped and aggregated. After the aggregating operation, 586: 593: 581: 140: 817: 747: 938: 862: 803: 913: 831: 810: 761: 733: 726: 606: 135: 139:
statement must only return rows where aggregate values meet the specified
838: 775: 712: 156: 845: 782: 768: 740: 719: 160:
are often confused by beginners, but they serve different purposes.
26: 789: 693: 688: 683: 678: 673: 668: 663: 923: 918: 908: 903: 898: 893: 658: 643: 629: 130: 919:
SQL Routines and Types for the Java Programming Language
598: 51:. Unsourced material may be challenged and removed. 936: 552:. The PostgreSQL Global Development Group. 2023 614: 183:To view the present condition formed by the 621: 607: 111:Learn how and when to remove this message 937: 176:applies to data read from tables, and 602: 537: 49:adding citations to reliable sources 20: 575:The HAVING and GROUP BY SQL clauses 13: 914:Information and Definition Schemas 14: 956: 568: 25: 36:needs additional citations for 1: 546:PostgreSQL 16.1 Documentation 530: 7: 904:Management of External Data 198: 10: 961: 924:XML-Related Specifications 899:Persistent Stored Modules 876: 855: 702: 636: 909:Object Language Bindings 393: 289: 205: 628: 587:SQL Aggregate Functions 146: 133:specifies that an SQL 281:sample tables in the 894:Call-Level Interface 592:May 3, 2017, at the 244:'2000-01-01' 45:improve this article 868:Relational database 391:, might look like: 580:2011-06-03 at the 932: 931: 877:ISO/IEC SQL parts 279:Referring to the 121: 120: 113: 95: 60:"Having" SQL 952: 848: 841: 834: 827: 820: 813: 806: 799: 792: 785: 778: 771: 764: 757: 750: 743: 736: 729: 722: 715: 623: 616: 609: 600: 599: 562: 561: 559: 557: 551: 541: 526: 523: 520: 517: 514: 511: 508: 505: 502: 499: 496: 493: 490: 487: 484: 481: 478: 475: 472: 469: 466: 463: 460: 457: 454: 451: 448: 445: 442: 439: 436: 433: 430: 427: 424: 421: 418: 415: 412: 409: 406: 403: 400: 397: 390: 386: 380: 377: 374: 371: 368: 365: 362: 359: 356: 353: 350: 347: 344: 341: 338: 335: 332: 329: 326: 323: 320: 317: 314: 311: 308: 305: 302: 299: 296: 293: 275: 272: 269: 266: 263: 260: 257: 254: 251: 248: 245: 242: 239: 236: 233: 230: 227: 224: 221: 218: 215: 212: 209: 195:clause is used. 193: 187: 179: 175: 171: 167: 163: 159: 153: 138: 127: 116: 109: 105: 102: 96: 94: 53: 29: 21: 960: 959: 955: 954: 953: 951: 950: 949: 935: 934: 933: 928: 872: 851: 844: 837: 830: 823: 816: 809: 802: 795: 788: 781: 774: 767: 760: 753: 746: 739: 732: 725: 718: 711: 698: 632: 627: 594:Wayback Machine 582:Wayback Machine 571: 566: 565: 555: 553: 549: 543: 542: 538: 533: 528: 527: 524: 521: 518: 515: 512: 509: 506: 503: 500: 497: 494: 491: 488: 485: 482: 479: 476: 473: 470: 467: 464: 461: 458: 455: 452: 449: 446: 443: 440: 437: 434: 431: 428: 425: 422: 419: 416: 413: 410: 407: 404: 401: 398: 395: 388: 384: 382: 381: 378: 375: 372: 369: 366: 363: 360: 357: 354: 351: 348: 345: 342: 339: 336: 333: 330: 327: 324: 321: 318: 315: 312: 309: 306: 303: 300: 297: 294: 291: 277: 276: 273: 270: 267: 264: 261: 258: 255: 252: 249: 246: 243: 240: 237: 234: 231: 228: 225: 222: 219: 216: 213: 210: 207: 201: 191: 185: 177: 173: 169: 165: 161: 155: 151: 149: 134: 125: 117: 106: 100: 97: 54: 52: 42: 30: 17: 12: 11: 5: 958: 948: 947: 930: 929: 927: 926: 921: 916: 911: 906: 901: 896: 891: 886: 880: 878: 874: 873: 871: 870: 865: 859: 857: 853: 852: 850: 849: 842: 835: 828: 821: 814: 807: 800: 793: 786: 779: 772: 765: 758: 751: 744: 737: 730: 723: 716: 708: 706: 700: 699: 697: 696: 691: 686: 681: 676: 671: 666: 661: 656: 651: 646: 640: 638: 634: 633: 626: 625: 618: 611: 603: 597: 596: 584: 570: 569:External links 567: 564: 563: 535: 534: 532: 529: 411:DepartmentName 394: 355:DepartmentName 295:DepartmentName 290: 206: 200: 197: 148: 145: 119: 118: 33: 31: 24: 15: 9: 6: 4: 3: 2: 957: 946: 943: 942: 940: 925: 922: 920: 917: 915: 912: 910: 907: 905: 902: 900: 897: 895: 892: 890: 887: 885: 882: 881: 879: 875: 869: 866: 864: 861: 860: 858: 854: 847: 843: 840: 836: 833: 829: 826: 822: 819: 815: 812: 808: 805: 801: 798: 794: 791: 787: 784: 780: 777: 773: 770: 766: 763: 759: 756: 752: 749: 745: 742: 738: 735: 731: 728: 724: 721: 717: 714: 710: 709: 707: 705: 701: 695: 692: 690: 687: 685: 682: 680: 677: 675: 672: 670: 667: 665: 662: 660: 657: 655: 652: 650: 647: 645: 642: 641: 639: 635: 631: 624: 619: 617: 612: 610: 605: 604: 601: 595: 591: 588: 585: 583: 579: 576: 573: 572: 548: 547: 540: 536: 392: 288: 286: 284: 204: 196: 194: 188: 181: 158: 144: 142: 137: 132: 128: 115: 112: 104: 101:February 2024 93: 90: 86: 83: 79: 76: 72: 69: 65: 62: –  61: 57: 56:Find sources: 50: 46: 40: 39: 34:This article 32: 28: 23: 22: 19: 945:SQL keywords 754: 554:. Retrieved 545: 539: 486:DepartmentID 474:DepartmentID 383: 346:DepartmentID 334:DepartmentID 282: 278: 202: 190: 189:clause, the 184: 182: 150: 124: 122: 107: 98: 88: 81: 74: 67: 55: 43:Please help 38:verification 35: 18: 556:February 8, 889:Foundation 863:Edgar Codd 531:References 456:Department 340:Department 322:Department 265:SaleAmount 223:SaleAmount 141:conditions 129:clause in 71:newspapers 16:SQL clause 884:Framework 939:Category 818:Truncate 790:Order by 748:Group by 704:Keywords 694:SQL:2023 689:SQL:2016 684:SQL:2011 679:SQL:2008 674:SQL:2006 669:SQL:2003 664:SQL:1999 637:Versions 590:Archived 578:Archived 516:empCount 444:Employee 438:empCount 328:Employee 316:Employee 238:SaleDate 199:Examples 186:GROUP BY 166:GROUP BY 856:Related 804:Prepare 495:deptNam 417:deptNam 285:example 85:scholar 832:Update 811:Select 762:Insert 755:Having 734:Delete 727:Create 659:SQL-92 654:SQL-89 649:SQL-86 644:SEQUEL 408:SELECT 396:SELECT 389:HAVING 385:HAVING 358:HAVING 292:SELECT 256:HAVING 253:DeptID 211:DeptID 208:SELECT 192:HAVING 178:HAVING 170:HAVING 152:HAVING 136:SELECT 126:HAVING 87:  80:  73:  66:  58:  839:Where 825:Union 776:Merge 550:(PDF) 507:WHERE 489:GROUP 423:COUNT 361:COUNT 349:GROUP 301:COUNT 247:GROUP 235:WHERE 232:Sales 174:WHERE 162:WHERE 157:WHERE 92:JSTOR 78:books 846:With 797:Over 783:Null 769:Join 741:From 720:Case 558:2024 519:> 480:dept 462:dept 453:JOIN 441:FROM 402:FROM 373:> 319:JOIN 313:FROM 283:Join 274:1000 271:> 229:FROM 154:and 64:news 630:SQL 510:grp 504:grp 468:emp 450:emp 259:SUM 217:SUM 147:Use 131:SQL 47:by 941:: 713:As 501:AS 492:BY 465:ON 459:AS 447:AS 435:AS 414:AS 352:BY 325:ON 250:BY 143:. 123:A 622:e 615:t 608:v 560:. 525:; 522:1 513:. 498:) 483:. 477:= 471:. 432:) 429:* 426:( 420:, 405:( 399:* 379:; 376:1 370:) 367:* 364:( 343:. 337:= 331:. 310:) 307:* 304:( 298:, 268:) 262:( 241:= 226:) 220:( 214:, 114:) 108:( 103:) 99:( 89:· 82:· 75:· 68:· 41:.

Index


verification
improve this article
adding citations to reliable sources
"Having" SQL
news
newspapers
books
scholar
JSTOR
Learn how and when to remove this message
SQL
SELECT
conditions
WHERE
sample tables in the Join example
PostgreSQL 16.1 Documentation
The HAVING and GROUP BY SQL clauses
Archived
Wayback Machine
SQL Aggregate Functions
Archived
Wayback Machine
v
t
e
SQL
SEQUEL
SQL-86
SQL-89

Text is available under the Creative Commons Attribution-ShareAlike License. Additional terms may apply.