martes, 6 de mayo de 2025

Date time type

 

Data TypeZero Value
DATE'0000-00-00'
TIME'00:00:00'
DATETIME'0000-00-00 00:00:00'
TIMESTAMP'0000-00-00 00:00:00'
YEAR0000


https://dev.mysql.com/doc/refman/8.0/en/date-and-time-types.html

Integer Types (Exact Value) - INTEGER, INT, SMALLINT, TINYINT, MEDIUMINT, BIGINT

 

Integer Types (Exact Value) - INTEGER, INT, SMALLINT, TINYINT, MEDIUMINT, BIGINT

MySQL supports the SQL standard integer types INTEGER (or INT) and SMALLINT. As an extension to the standard, MySQL also supports the integer types TINYINTMEDIUMINT, and BIGINT. The following table shows the required storage and range for each integer type.

Table 13.1 Required Storage and Range for Integer Types Supported by MySQL

TypeStorage (Bytes)Minimum Value SignedMinimum Value UnsignedMaximum Value SignedMaximum Value Unsigned
TINYINT1-1280127255
SMALLINT2-3276803276765535
MEDIUMINT3-83886080838860716777215
INT4-2147483648021474836474294967295
BIGINT8-2630263-1264-1

viernes, 18 de abril de 2025

MySQL ANY ALL IN

mysql> select  4 >any(select 33  as V UNION ALL select 11) as R;

+---+

| R |

+---+

| 0 |

+---+

1 row in set (0.00 sec)


mysql> select  34 >any(select 33  as V UNION ALL select 11) as R;

+---+

| R |

+---+

| 1 |

+---+

1 row in set (0.01 sec)

-----------
ALL

mysql> select  34 >ALL(select 33  as V UNION ALL select 11) as R;
+---+
| R |
+---+
| 1 |
+---+
1 row in set (0.00 sec)


https://dev.mysql.com/doc/refman/8.4/en/any-in-some-subqueries.html

Syntax:

operand comparison_operator ANY (subquery)
operand IN (subquery)
operand comparison_operator SOME (subquery)

Where comparison_operator is one of these operators:

=  >  <  >=  <=  <>  !=

MySQL exists

 select  exists  (select  'A' where 5>10) as R;

+---+

| R |

+---+

| 0 |

+---+


Because     the evaluated query return   empty set, if return any value doesn't matter the value   it will return  1, doesn't matter if is null or 0.

select  'A' where 5>10;
Empty set (0.00 sec)


------------------------    exists   here will return 1

select  exists  (select  NULL) as R;
+------+
| R    |
+------+
|    1 |
+------+
1 row in set (0.00 sec)

-


 select  exists  (select  0) as R;
+---+
| R |
+---+
| 1 |
+---+


select 'Ambiorix' where exists(select 1);
+----------+
| Ambiorix |
+----------+
| Ambiorix |
+----------+

MySQL IF

mysql> select if(10>8,'A','B') as result;

+--------+

| result |

+--------+

| A      |

+--------+


--------------
mysql> select if(10>15,'A','B') as result;
+--------+
| result |
+--------+
| B      |
+--------+


MySQL case

mysql> set @i=4;

 mysql> select case @i

    -> when @i>3 then'A'

    -> else 'B'

    -> end as t;



------------
mysql> select case
    -> when 5>4 then  'A'
    -> when 5<6 then 'B'
    -> else 'C'
    -> end as t;
+---+

lunes, 17 de marzo de 2025

Functions and Operators

  Functions and Operators


https://dev.mysql.com/doc/refman/8.4/en/functions.html




Data type


https://dev.mysql.com/doc/refman/8.4/en/data-types.html