{
  "$type": "site.standard.document",
  "bskyPostRef": {
    "cid": "bafyreie2quxgdad4vancvhozbl6oai3pwuw5ag3ftk6vjnadha5nkk4ode",
    "uri": "at://did:plc:25rdn5elo5izoxrmtis34zuk/app.bsky.feed.post/3mprdl5eyaq62"
  },
  "coverImage": {
    "$type": "blob",
    "ref": {
      "$link": "bafkreiax73m6pvrptga7dxo2rw4ngbnkk5tx7caowz2xwxde3es5rebese"
    },
    "mimeType": "image/webp",
    "size": 58800
  },
  "path": "/juhi_singhal_7d7fb8634472/5-sql-interview-questions-that-trip-up-beginners-5cmi",
  "publishedAt": "2026-07-03T19:49:14.000Z",
  "site": "https://dev.to",
  "tags": [
    "sql",
    "career",
    "database",
    "interview",
    "DBMS & SQL interview prep PDF"
  ],
  "textContent": "#  5 SQL Interview Questions That Trip Up Beginners\n\nIf you're prepping for a tech interview, SQL usually feels \"easy\" until you're actually in the room. Here are 5 questions that look simple on paper but catch people off guard — plus quick explanations so you don't get caught out.\n\n##  1. What's the difference between WHERE and HAVING?\n\nMost people say \"WHERE filters rows, HAVING filters groups\" and stop there — which is correct, but interviewers often follow up with: _why can't you use an aggregate function like COUNT() inside WHERE?_\n\nThe answer: WHERE is applied **before** GROUP BY, while the aggregate values don't exist yet at that stage. HAVING runs **after** grouping, once the aggregates are calculated. That's why:\n\n\n\n    SELECT Country, COUNT(CustomerID)\n    FROM Customers\n    GROUP BY Country\n    HAVING COUNT(CustomerID) > 5;\n\n\nworks, but putting `COUNT(CustomerID) > 5` in a WHERE clause would throw an error.\n\n##  2. Can a table have more than one primary key?\n\nTrick question. A table can have only **one** primary key — but that primary key can be made up of multiple columns. This is called a **composite key**. So the answer is \"one primary key, which may be composite,\" not \"yes.\"\n\n##  3. What happens if you JOIN two tables with no matching rows?\n\nWith an INNER JOIN, you get zero rows back — nothing at all, even if both tables have data. Beginners often expect _some_ output. If the interviewer wants unmatched rows preserved, that's when you'd reach for a LEFT, RIGHT, or FULL OUTER JOIN instead.\n\n##  4. Why can't you compare a column to NULL using `=`?\n\n`WHERE Address = NULL` will never return any rows — not because there's no NULL data, but because NULL isn't a value you can compare with `=` or `<>`. SQL treats NULL as \"unknown,\" and unknown compared to anything is also unknown (never true). You have to use `IS NULL` or `IS NOT NULL` instead.\n\n##  5. What's the difference between DELETE and TRUNCATE?\n\nBoth remove data, but:\n\n  * **DELETE** is a DML command, can use a WHERE clause to remove specific rows, and can be rolled back.\n  * **TRUNCATE** is a DDL command, removes _all_ rows at once, resets identity/auto-increment counters, and in most databases cannot be rolled back once committed.\n\n\n\nIf an interviewer asks \"which is faster,\" the answer is TRUNCATE — since it doesn't log individual row deletions the way DELETE does.\n\nThese are the kind of gotchas that separate \"I know SQL\" from \"I can survive a live interview.\" If you want the full breakdown — ER diagrams, normalization, transactions, ACID, joins, and the complete SQL syntax reference in one place — I put together a **DBMS & SQL interview prep PDF** with all of it.\n\nWhat's a SQL question that caught _you_ off guard in an interview? Drop it in the comments — always curious what people are actually being asked out there.",
  "title": "5 SQL Interview Questions That Trip Up Beginners"
}