Menu

Learn SQL and Databases with Practical Examples

SQLiz is a practical learning library for SQL and database tools. Browse query examples for MySQL, PostgreSQL, SQLite, MariaDB, and SQL Server, alongside references and setup guides for Oracle, MongoDB, Redis, and more. Use site search to find a function or task, choose a database tutorial below, or browse all articles for installation and programming guides.

How to Check Whether a Table Exists in MySQL

Check for a MySQL table with SHOW TABLES or INFORMATION_SCHEMA, or create it safely with IF NOT EXISTS—without assuming the existing schema matches.

Delete Duplicate Rows in MySQL and Keep One Record

Preview duplicate rows, delete extras with a self-join, verify the result in an InnoDB transaction, and add a unique key to prevent repeats.

4 Ways to Replace NULL with a Different Value in MySQL

Compare MySQL COALESCE(), IFNULL(), IF(), and CASE for returning a fallback value when an expression is NULL.

4 Ways to Find Duplicate Rows in MySQL

Find duplicate MySQL values with GROUP BY and HAVING, return matching rows, count duplicates with a window function, or identify extra rows with ROW_NUMBER().

3 Ways to Get the First Day of the Month in MySQL

Get the first day of the current or a specified month in MySQL with DATE_SUB(), DATE_FORMAT(), or LAST_DAY().

3 Ways to Find a Substring's Position in MySQL

Compare MySQL LOCATE(), INSTR(), and POSITION() to find a substring’s 1-based position, including argument order and start-position behavior.

2 Ways to List Stored Procedures in MySQL

List MySQL stored procedures with SHOW PROCEDURE STATUS or INFORMATION_SCHEMA.ROUTINES, filter by database, and understand privilege limits.

PostgreSQL Error 42P01: Relation Does Not Exist

Fix PostgreSQL SQLSTATE 42P01 by checking the database, search_path, schema access, relation name, and quoted identifier case.

PostgreSQL Error 42703: Column Does Not Exist

Troubleshoot PostgreSQL SQLSTATE 42703 by checking column names, table aliases, quoted identifier case, and SELECT output aliases.

PostgreSQL Error 42702: Column Reference Is Ambiguous

Fix PostgreSQL SQLSTATE 42702 by qualifying shared column names with table aliases and checking each table in a join.

PostgreSQL Error 42601: Syntax Error

Troubleshoot PostgreSQL SQLSTATE 42601 by reading the reported line and position, isolating the statement, and checking nearby SQL syntax.

PostgreSQL Error 42501: Permission Denied

Diagnose PostgreSQL SQLSTATE 42501 by checking the active role, schema access, table or sequence privileges, and row security.

PostgreSQL Error 28P01: Password Authentication Failed

Troubleshoot PostgreSQL SQLSTATE 28P01 by checking the connection target, role, stored secret, and matching pg_hba.conf rule.

PostgreSQL Error 23505: Duplicate Key Violates Unique Constraint

Diagnose PostgreSQL SQLSTATE 23505 by identifying the unique key, finding conflicting rows, and choosing an intentional ON CONFLICT action.

PostgreSQL Error 23503: Foreign Key Violation

Diagnose PostgreSQL SQLSTATE 23503 by checking missing parent rows, blocked parent deletes, and existing rows that violate a new foreign key.

MySQL Error 2013: Lost Connection During Query

Troubleshoot MySQL Error 2013 by checking network drops, server logs, transfer timeouts, and large results, then verify writes before retrying.

MySQL Error 2006: MySQL Server Has Gone Away

Fix MySQL Error 2006 by checking idle connection timeouts, max_allowed_packet, server restarts, and stale application connections.

MySQL Error 2005: Unknown MySQL Server Host

Fix MySQL Error 2005 by checking the hostname, DNS from the client environment, and MySQL connection options or application settings.

MySQL Error 2003: Can't Connect to MySQL Server

Fix MySQL Error 2003 by checking the server, host and port, TCP/IP settings, bind_address, skip_networking, and network access rules.

MySQL Error 2002: Can't Connect Through Socket

Fix MySQL Error 2002 by checking whether mysqld runs, matching client and server socket paths, and testing TCP/IP separately.

MySQL Error 1130: Host Is Not Allowed to Connect

Fix MySQL Error 1130 by matching the client host to a MySQL user@host account and checking DNS, skip_name_resolve, and least-privilege grants.

MySQL Error 1054: Unknown Column

Fix MySQL Error 1054 by checking real column names, table aliases, SELECT alias scope, and derived-table output columns.

MySQL Error 1146: Table Doesn't Exist (42S02)

Fix MySQL Error 1146 (42S02) by checking the selected database, exact table name and case, and whether the table migration ran.

MySQL Error 1061: Duplicate Key Name (42000)

Fix MySQL Error 1061 by inspecting existing indexes and migrations before adding or renaming an index. Learn how it differs from duplicate rows.

MySQL Error 1060: Duplicate Column Name (42S21)

Fix MySQL Error 1060 (42S21) by checking the table definition before adding or redefining a column, and identify duplicate schema migrations.

MySQL Error 1049: Unknown Database (42000)

Fix MySQL Error 1049 (42000) by checking the database name, server, letter case, and account visibility before creating or selecting a database.

MySQL Error 1046: No Database Selected (3D000)

Fix MySQL Error 1046 (3D000) by selecting a database with USE, qualifying table names, or setting the database in your client connection.

MySQL Error 1045: Access Denied for User (28000)

Fix MySQL Error 1045 by checking the password, user@host account, server and protocol, and account authentication or lock status.

MySQL Error 1044: Access Denied to Database (42000)

Fix MySQL Error 1044 by checking the authenticated account and granting only the database or table privileges the operation needs.

MySQL Error 1215: Cannot Add Foreign Key Constraint

Diagnose MySQL Error 1215 with a foreign-key checker for numeric and character columns, engines, and indexes, then inspect InnoDB’s latest error.