Having has some differences in Oracle and mysql

Source: Internet
Author: User

Having has some differences in Oracle and mysql

In Oracle, having must be used in combination with group by, but in mysql, the situation is different and can be used separately.

C: \ Documents ents and Settings \ guogang> sqlplus test/test

SQL * Plus: Release 10.2.0.1.0-Production on Tuesday August 12 09:09:58 2014
Copyright (c) 1982,200 5, Oracle. All rights reserved.
Connect:
Oracle Database 11g Enterprise Edition Release 11.2.0.1.0-64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options

SQL> select * from test1 having owner = 'sys ';
Select * from test1 having owner = 'sys'
*
Row 3 has an error:

ORA-00979: Not a group by expression

SQL> select owner, count (1) from test1 group by owner having owner = 'sys ';
Owner count (1)
----------------------------------------

SYS 30754

Mysql> select * from test having id> 98;
+ ------ + ------------- +
| Id | create_time |
+ ------ + ------------- +
| 99 | 2014-08-12 |
| 100 |
+ ------ + ------------- +
2 rows in set (0.00 sec)

Mysql> select id, count (1) from test group by id having id> 98;
+ ------ + ---------- +
| Id | count (1) |
+ ------ + ---------- +
| 99 | 1 |
| 1 | 100 |
+ ------ + ---------- +
2 rows in set (0.00 sec)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.