Category: Introduction to MySQL

Introduction to MySQL

enum values MySql

enum values MySql

An ENUM is a string object with a value chosen from a list of permitted values that are enumerated explicitly in the column specification at table creation time.   An enumeration value must be...

Using Logical Operators

Using Logical Operators

You can also use the logical operators AND, OR, and NOT in your MySQL WHERE queries to further narrow down your selections. Following Example shows one instance of each, but you can mix and...

Joins in MySql

Joins in MySql

It is quite normal to maintain multiple tables within a database, each holding a different type of information. For example, consider the case of a customers table that needs to be able to be...

GROUP BY MySql

GROUP BY MySql

In a similar fashion to ORDER BY, you can group results returned from queries using GROUP BY, which is good for retrieving information about a group of data. For example, if you want to...

ORDER BY MySql

ORDER BY MySql

ORDER BY sorts returned results by one or more columns in ascending or descending order. As you can see, the first query returns the publications by author in ascending alphabetical order (the default), and...

Update Clause MySql

Update Clause MySql

This construct allows you to update the contents of a field. If you wish to change the contents of one or more fields, you need to first narrow in on just the field or...

LIMIT clause MySql

LIMIT clause MySql

The LIMIT qualifier enables you to choose how many rows to return in a query, and where in the table to start returning them. When passed a single parameter, it tells MySQL to start...

WHERE clause MySql

WHERE clause MySql

The WHERE keyword enables you to narrow down queries by returning only those where a certain expression is true. Using Like to match patterns You can also do pattern matching for your searches using...

DELETE clause MySql

DELETE clause MySql

When you need to remove a row from a table, use the DELETE command. Its syntax is similar to the SELECT command and allows you to narrow down the exact row or rows to...

SELECT DISTINCT MySql

SELECT DISTINCT MySql

This qualifier (and its synonym DISTINCTROW) allows you to weed out multiple entries when they contain the same data. For instance, suppose that you want a list of all authors in the table. If...

SELECT COUNT MySql

SELECT COUNT MySql

Another replacement for the something parameter is COUNT, which can be used in many ways. Consider following Example , it displays the number of rows in the table by passing * as a parameter,...

Querying a MySQL Database

Querying a MySQL Database

So far we’ve created a MySQL database and tables, populated them with data, and added indexes to make them fast to search. Now it’s time to look at how these searches are performed, and...

Primary keys MySql

Primary keys MySql

So far we have created the table classics and ensured that MySQL can search it quickly by adding indexes, but there’s still something missing. All the publications in the table can be searched, but...

Indexes in mysql

Indexes in mysql

As things stand, the table classics works and can be searched without problem by MySQL—until it grows to more than a couple hundred rows, that is. At that point, database accesses will get slower...

Deleting a table

Deleting a table

Deleting a table is very easy indeed. But, because I don’t want you to have to reenter all the data for the classics table, let’s quickly create a new table, verify its existence, and...

Removing a column

Removing a column

Actually, upon reflection, maybe the page count column pages isn’t actually all that useful for this particular database, so here’s how to remove that column using the DROP keyword: