• Skip to main content
  • Skip to primary sidebar

Founder at work

Master the skills to create and launch your next SaaS company

  • About Me
  • Reviews
  • Resources
  • Community
  • Contact
  • Lessons
  • Series
  • Search
  • Login

Simple MySQL statments that get used.

April 10, 2013 by Rick Hernandez Leave a Comment

mysql> show tables;
+----------------------+
| Tables_in_ricardohDB |
+----------------------+
| Customer             |
| FavoriteThings       |
| Orders               |
| SalesPerson          |
| phoneBook            |
+----------------------+
5 rows in set (0.04 sec)

mysql> select MAX(age) AS
    -> age FROM SalesPerson;
+------+
| age  |
+------+
|   63 |
+------+
1 row in set (0.00 sec)

mysql> SELECT age, salary FROM SalesPerson;
+------+--------+
| age  | salary |
+------+--------+
|   63 | 120000 |
|   38 |  42000 |
|   26 |  36000 |
|   42 |  50000 |
|   59 | 118000 |
|   27 |  34000 |
+------+--------+
6 rows in set (0.01 sec)

mysql> SELECT distinct age, salary FROM SalesPerson;
+------+--------+
| age  | salary |
+------+--------+
|   63 | 120000 |
|   38 |  42000 |
|   26 |  36000 |
|   42 |  50000 |
|   59 | 118000 |
|   27 |  34000 |
+------+--------+
6 rows in set (0.00 sec)

mysql> SELECT name FROM SalesPerson WHERE (age < 30);
+-------+
| name  |
+-------+
| Jones |
| Kobad |
+-------+
2 rows in set (0.00 sec)

mysql> SELECT name FROM SalesPerson INNER JOIN Orders WHERE(SalesPerson.Name = Orders.SalesPersonName) AND Orders.CustName = "Abernathy Construction";
+--------+
| name   |
+--------+
| Zenith |
| Jones  |
| Murphy |
+--------+
3 rows in set (0.01 sec)

mysql> SELECT name FROM SalesPerson WHERE (Salary > 49999 AND Salary < 100000);
+--------+
| name   |
+--------+
| Murphy |
+--------+
1 row in set (0.00 sec)

mysql> SELECT name from SalesPerson WHERE age BETWEEN 50 AND 59;
+--------+
| name   |
+--------+
| Zenith |
+--------+
1 row in set (0.00 sec)


mysql> SELECT name from SalesPerson WHERE age LIKE '5%';
+--------+
| name   |
+--------+
| Zenith |
+--------+
1 row in set (0.00 sec)

mysql> SELECT name FROM Customer WHERE city LIKE '%s';
+---------------------+
| name                |
+---------------------+
| Tri-City Builders   |
| Amalgamated Housing |
+---------------------+
2 rows in set (0.00 sec)


mysql> SELECT DISTINCT name,salary FROM SalesPerson INNER JOIN Orders WHERE(SalesPerson.Name = Orders.SalesPersonName) AND Orders.CustName != "Abernathy Construction" ORDER BY salary DESC;
+-------+--------+
| name  | salary |
+-------+--------+
| Abel  | 120000 |
| Jones |  36000 |
+-------+--------+
2 rows in set (0.00 sec)

mysql> SELECT table_name, table_rows
    -> FROM INFORMATION_SCHEMA.TABLES
    -> WHERE table_schema = 'ricardohDB'
    -> AND table_name = 'Orders';
+------------+------------+
| table_name | table_rows |
+------------+------------+
| Orders     |          7 |
+------------+------------+
1 row in set (0.00 sec)


mysql> SELECT COUNT(SalesPersonName)
    -> AS NumeberofOrders FROM Orders
    -> ;
+-----------------+
| NumeberofOrders |
+-----------------+
|               7 |
+-----------------+
1 row in set (0.00 sec)

mysql> SELECT COUNT(DISTINCT SalesPersonName)
    -> AS NumeberofOrders FROM Orders;
+-----------------+
| NumeberofOrders |
+-----------------+
|               4 |
+-----------------+
1 row in set (0.00 sec)

mysql> SELECT AVG(age) FROM SalesPerson;
+----------+
| AVG(age) |
+----------+
|  42.5000 |
+----------+
1 row in set (0.00 sec)

mysql> SELECT name,MAX(age) AS LargestAge FROM SalesPerson;
+------+------------+
| name | LargestAge |
+------+------------+
| Abel |         63 |
+------+------------+
1 row in set (0.00 sec)

Click to access mysql-cheat-sheet-v1.pdf

Rick Hernandez

I always had a passion for the field of STEM (Science, Technology, Engineering, and Math) and I knew I wanted to do something to make a difference in the world. I just didn’t know where to start. I was an immigrant in a new country, grew up in a tough environment, and wasn’t sure how… Read More

Share this:

  • Click to share on Twitter (Opens in new window)
  • Click to share on Facebook (Opens in new window)

Related

Filed Under: MySQL, Programming

Primary Sidebar

Learn How To Take Your Idea And Convert It Into An App From Scratch Even If You Have Never Written A Single Line Of Code.

  • How to Find Your Next Great App Idea
  • The Secret To Getting PAID To Build Your Own App
  • How To Create Your App (SaaS, Mobile, VR, AR, Game)
  • How To Monetize Your Apps
Learn More
4.82 Ratings

Copyright © 2025 · JSecademy Blog Theme on Genesis Framework · WordPress · Log in