Using the MySQL SELECT statement to only show records that are a certain type.

Posted: August 16, 2012. At: 11:37 PM. This was 5 years ago. Post ID: 4439
Page permalink.
WordPress uses cookies, or tiny pieces of information stored on your computer, to verify who you are. There are cookies for logged in users and for commenters. These cookies expire two weeks after they are set.

Following on from my previous posting that covered setting up a MySQL database, here is a simple query that returns records that match a certain type.

mysql> select * from operatingsystems where Type = "Windows";
+------+-------------+---------+-----------+
| OsID | Name        | Type    | vendor    |
+------+-------------+---------+-----------+
|    1 | Windows 3.0 | Windows | Microsoft |
|    2 | Windows 3.1 | Windows | Microsoft |
|    3 | Windows `95 | Windows | Microsoft |
|    4 | Windows `98 | Windows | Microsoft |
|   29 | Windows 7   | Windows | Microsoft |
+------+-------------+---------+-----------+
5 rows in set (0.00 sec)

Another query.

mysql> select * from operatingsystems where vendor = "SUSE";
+------+-----------------+-------+--------+
| OsID | Name            | Type  | vendor |
+------+-----------------+-------+--------+
|    9 | SUSE Linux 9.2  | Linux | SUSE   |
|   10 | SUSE Linux 10   | Linux | SUSE   |
|   11 | SUSE Linux 10.2 | Linux | SUSE   |
+------+-----------------+-------+--------+
3 rows in set (0.00 sec)

Deleting a certain row from our table.

mysql> delete from operatingsystems where Name = "SUSE Linux 10";
Query OK, 1 row affected (0.04 sec)

Our poor table after losing one row…

mysql> select * from operatingsystems;
+------+--------------------+---------+--------------------+
| OsID | Name               | Type    | vendor             |
+------+--------------------+---------+--------------------+
|    1 | Windows 3.0        | Windows | Microsoft          |
|    2 | Windows 3.1        | Windows | Microsoft          |
|    3 | Windows `95        | Windows | Microsoft          |
|    4 | Windows `98        | Windows | Microsoft          |
|    5 | Redhat 6.2         | Linux   | Redhat             |
|    6 | FreeBSD 6.2        | UNIX    | FreeBSD Developers |
|    7 | Mandrake Linux 9.0 | Linux   | Mandrake           |
|    8 | Mandrake Linux 9.2 | Linux   | Mandrake           |
|    9 | SUSE Linux 9.2     | Linux   | SUSE               |
|   11 | SUSE Linux 10.2    | Linux   | SUSE               |
|   12 | Ubuntu 8.10        | Linux   | Canonical          |
|   13 | Ubuntu 9.04        | Linux   | Canonical          |
|   14 | Ubuntu 9.10        | Linux   | Canonical          |
|   15 | Ubuntu 10.04       | Linux   | Canonical          |
|   16 | Ubuntu 10.10       | Linux   | Canonical          |
|   17 | Ubuntu 11.04       | Linux   | Canonical          |
|   18 | Ubuntu 11.10       | Linux   | Canonical          |
|   19 | Ubuntu 12.04       | Linux   | Canonical          |
|   20 | Ubuntu 12.10       | Linux   | Canonical          |
|   21 | Linux Mint 8       | Linux   | Mint               |
|   22 | Linux Mint 9       | Linux   | Mint               |
|   23 | Linux Mint 10      | Linux   | Mint               |
|   24 | Linux Mint 12      | Linux   | Mint               |
|   25 | Linux Mint 13      | Linux   | Mint               |
|   26 | Fedora Core 14     | Linux   | Fedora Developers  |
|   27 | Fedora Core 15     | Linux   | Fedora Developers  |
|   28 | Fedora Core 17     | Linux   | Fedora Developers  |
|   29 | Windows 7          | Windows | Microsoft          |
+------+--------------------+---------+--------------------+
28 rows in set (0.01 sec)

That is how easy it is to manage your database with MySQL on Linux or Windows. Database management is not very hard after all. Just remember there is not hand-holding with a database management system. So be careful and backup often.

No comments have been made. Use this form to start the conversation :)

Leave a Reply