Ask Programiz - Human Support for Coding Beginners
Explore questions from fellow beginners answered by our human experts. Have some doubts about coding fundamentals? Enroll in our course and get personalized help right within your lessons.
If the table already exists but the columns are different, CREATE TABLE IF NOT EXISTS wonât try to âfixâ or update anything. It simply checks: does a table named Customers already exist? If yes, it stops right there.
So what this really means is:
No error is thrown
No changes are made
The existing table stays exactly as it is, even if your new
CREATE TABLEstatement has different columns
If you actually want to change the tableâs structure (add/remove columns, change data types, etc.), youâd use something like ALTER TABLE, or youâd drop and recreate the table if thatâs appropriate for your setup.
Hope that helps. Feel free to reach out if you have any more questions.

Hello Omar, really nice question.
The logic behind SELECT in SQL is actually pretty simple once you see what problem it solves. A database table is like a giant spreadsheet. Most of the time, you donât need every single piece of information in that table â you just need certain columns or certain rows.
SELECT is how you tell the database: âShow me only the parts I care about.â
For example, if a table has ten different columns but you only want to see age and country, you can write:
SELECT age, country
FROM Customers;
Now the database gives you just those two columns instead of the whole table. Itâs efficient, itâs cleaner, and it makes it easier to work with your data.
So the real logic is:
Ask for the specific data you want instead of taking everything.
If you want to dig deeper into filtering, sorting, or selecting rows, Iâm happy to help you explore that next.

Hello Omar, really nice question.
Using * in SQL grabs every column in the table. It works, but it often gives you more data than you actually need. When you switch to something like:
SELECT age
FROM Customers;
youâre telling the database exactly what you want. That makes your query faster, easier to understand, and avoids pulling in extra or sensitive information by accident.
So the idea is simple:
Only ask for the columns you actually need.
It keeps the query clean and efficient.
If you have further questions, I'm here to help.

Hello Rishabh, really nice question.
When you use GROUP BY, youâre asking SQL to take many rows and squeeze them into one row per group. In your case, the groups are countries. That means all customers from the same country get combined so you can calculate something about the whole group â like the average age.
Hereâs the key idea:
A grouped result needs one clear value per group.
The country has one value, the average age has one value⊠but the name does not. There are many customer names in each country, so SQL doesnât know which one to show.
Thatâs why this works:
SELECT country, AVG(age) AS average_age
FROM Customers
GROUP BY country;
But adding a name does not make sense unless you also group by it or aggregate it. If you tried:
SELECT country, name, AVG(age)
SQL would ask: âWhich name should I show for this country? There are many.â
Once you see it that way, it becomes clear:
GROUP BY is for summaries, not individual details.
If you have further questions, I'm here to help.

Hello OTM Egytrans, really nice question.
In SQL, DISTINCT doesnât belong to just one column once you write it â it applies to the entire set of selected columns together.
So:
SELECT DISTINCT col1
FROM your_table;
gives you unique values of col1.
But:
SELECT DISTINCT col1, col2
FROM your_table;
now treats each (col1, col2) pair as a single combination. SQL removes duplicate rows where both col1 and col2 are the same. It does not make col1 distinct while allowing col2 to vary freely in that same query.
That means thereâs no direct way to say âmake column 1 distinct, but donât apply DISTINCT to column 2â in one simple SELECT DISTINCT col1, col2 statement.
If you want âdistinct by column 1â and still show something from column 2, you usually:
either decide which row per
col1you want (for example, withMIN(col2)orMAX(col2)plusGROUP BY col1), oruse more advanced techniques (like window functions) depending on your database.
But the key idea is:DISTINCT always works on the whole selected row, not just a single column unless you only select that one.
If you have further questions, I'm here to help.

Hi Rishabh,
Good question â I see where the confusion is coming from.
Your query is counting how many distinct brands exist in the filtered data. Since you're filtering for ByteCore and ZapTech, there are clearly two distinct brands. So COUNT(DISTINCT brand) should return 2 â and it does.
But if you're getting 3 as the result, then the issue might be that youâre actually counting distinct product names, not brands.
If your intention is to count unique products under those brands, you should change the query to this:
SELECT COUNT(DISTINCT name) AS distinct_product
FROM Products
WHERE brand = 'ByteCore' OR brand = 'ZapTech';
This will count the number of different product names from those two brands â for example: keyboard, mouse, and headphone â which would give you 3.
So check what exactly youâre trying to count: brands or product names. That makes all the difference.
If you have more questions, Iâm here to help.


Hi Bruno,
Great question. Both NOT and <> / != can be used to exclude values, but there are cases where NOT is preferred for clarity.
Hereâs when using NOT can make more sense:
With complex conditions
When you're excluding entire conditions or expressions,NOTcan make things clearer:WHERE NOT (age < 18 OR country = 'UAE')With subqueries
NOT INandNOT EXISTSare common and often easier to read than alternatives:WHERE NOT EXISTS (SELECT * FROM ...)Improved readability
In some cases,AND NOT country = 'UAE'might be easier to read thancountry != 'UAE', especially in long conditions.
That said, if you're just comparing single values, <> or != is shorter and works just as well:
WHERE country != 'UAE'
In the end, it comes down to readability and personal or team preference. Functionally, both work â pick the one that makes your intent clearest.
If youâve got more questions, Iâm here to help.

Hi Tom,
Yes, exactly â WHERE always comes before GROUP BY in SQL.
Hereâs why: the WHERE clause filters the rows before any grouping happens. So only the rows that match your condition are included in the groups.
Letâs say you have this query:
SELECT department, MIN(age) AS min_age, MAX(age) AS max_age
FROM Employees
WHERE department <> 'Marketing'
GROUP BY department;
First, SQL filters out all rows where the department is 'Marketing'. Then it groups the remaining rows by department and calculates the min and max age for each group.
If you applied the WHERE after GROUP BY, it wouldnât work â because WHERE doesnât operate on groups. Thatâs what HAVING is for, if you ever need to filter after grouping.
So yes, WHERE always comes first.
If you have more questions, I am here to help.

Hi Chika,
int stands for integer, which means whole numbers â no decimals. Examples include 5, 42, or -100.
In most programming languages, including C and C++, int is used to declare variables that store whole numbers:
int age = 25;
That line creates a variable named age that holds the value 25.
If you have more questions, I am here to help.

Hi Julia,
Yes, thatâs correct â if you donât use a TCL command like COMMIT, your changes may not be saved permanently.
When you run SQL statements like INSERT, UPDATE, or DELETE, the changes happen in a temporary state called a transaction. They're not actually saved to the database until you explicitly commit them:
COMMIT;
If you donât run COMMIT, and you close the connection or something goes wrong, those changes can be rolled back â meaning theyâre lost.
You can also use:
ROLLBACKto undo changesSAVEPOINTto mark specific points you might roll back to
So yes â using TCL commands like COMMIT is what finalizes your changes.
If you have more questions, I am here to help.
Our Experts
Sudip BhandariHead of Growth/Marketing
Apekchhya ShresthaSenior Product Manager
Kelish RaiTechnical Content Writer
Abhilekh GautamSystem Engineer
Palistha SinghTechnical Content Writer
Sarthak BaralSenior Content Editor
Saujanya Poudel
Abhay Jajodia
Nisha SharmaTechnical Content Writer
Udayan ShakyaTechnical Content Writer
