SQL and regular expressions look intimidating at first, but a handful of patterns cover most everyday needs. SQL lets you ask questions to a database; regex lets you find and check patterns in text. Here are the basics with examples you can copy, and a free AI SQL and regex generator that writes them from plain English.
Part 1: SQL basics
Imagine a table called orders with the columns id, customer, country, amount and order_date.
SELECT: choose the columns
SELECT customer, amount FROM orders;
WHERE: filter the rows
SELECT * FROM orders WHERE country = 'France' AND amount > 100;
ORDER BY and LIMIT: sort and keep the top
SELECT customer, amount FROM orders ORDER BY amount DESC LIMIT 10;
GROUP BY: totals and averages
SELECT country, COUNT(*) AS orders, SUM(amount) AS revenue FROM orders GROUP BY country ORDER BY revenue DESC;
Dates: sales per month
SELECT DATE_FORMAT(order_date, '%Y-%m') AS month, SUM(amount) FROM orders GROUP BY month; (MySQL). In PostgreSQL, use DATE_TRUNC('month', order_date).
JOIN: combine two tables
With a customers table:
SELECT o.id, c.name, o.amount FROM orders o JOIN customers c ON c.id = o.customer_id;
A LEFT JOIN keeps all rows from the first table, even without a match.
Be careful with UPDATE and DELETE
DELETE FROM orders WHERE id = 42; Without a WHERE clause, the whole table is affected. Always run a SELECT with the same WHERE first, and keep a backup.
Part 2: regex basics
A regular expression is a pattern that describes text. The most useful symbols:
.any character\da digit,\wa letter, digit or underscore,\sa space+one or more,*zero or more,?optional{3}exactly 3 times,{2,5}between 2 and 5 times[abc]one of these characters,[^abc]anything except them^start of the text,$end of the text( )a group you can capture,|or
Common patterns
- Simple email check:
^[\w.+-]+@[\w-]+\.[\w.]+$ - Date YYYY-MM-DD:
^\d{4}-\d{2}-\d{2}$ - French postal code:
^\d{5}$ - Hashtags in a text:
#\w+ - Multiple spaces:
\s{2,}(replace with one space)
Where to use regex
In code (JavaScript, Python, PHP), in text editors like VS Code to search and replace, in Google Sheets with REGEXMATCH and REGEXEXTRACT, and in many tools for form validation.
Tips to learn faster
- Start from a real question you need to answer.
- Test on a small sample before running on everything.
- Read queries out loud: SQL is close to English.
- For regex, test with examples that should match and examples that should not.
Let AI write it for you
Describe what you need in plain English, for example “monthly revenue per country for 2025” or “a regex to find phone numbers in a text”, to our free AI SQL and regex generator. You get the code, an explanation of each part and examples. You can also paste existing code to understand or fix it. For spreadsheets, try the Excel formula generator, and for other programming tasks, AI for coding.
Frequently asked questions
Is SQL hard to learn?
No. With SELECT, WHERE, GROUP BY and JOIN, you can already answer most business questions.
Are regex the same in every language?
The basics are the same, but some advanced features differ. Always say which language you use.
Can AI run my query?
No, it only writes the code. You run it in your own database tool.
Try it now: use our free AI SQL and Regex Generator, no sign-up needed.

