{
  "deck_name": "SQL Fundamentals",
  "cards": [
    { "question": "In a relational database, what does a table represent?", "answer": "A relation of records organized into rows and named columns; each row represents one record and each column a field." },
    { "question": "What does SELECT do in a basic SQL query?", "answer": "It chooses the columns or expressions to return in the query result." },
    { "question": "What does FROM specify in a basic SELECT query?", "answer": "The table or tables from which the query reads rows." },
    { "question": "What does WHERE do?", "answer": "It filters input rows to keep only those that satisfy a condition, before grouping and aggregation." },
    { "question": "Write a query that returns the name of each active student, alphabetically.", "answer": "SELECT name FROM students WHERE active = TRUE ORDER BY name;" },
    { "question": "What is the purpose of ORDER BY?", "answer": "It sorts the rows in the result. ASC is ascending order and DESC is descending order; ascending is the default in PostgreSQL." },
    { "question": "In PostgreSQL, what does LIMIT 10 do to a query result?", "answer": "It returns at most the first 10 rows after the other query operations and any requested ordering." },
    { "question": "Why should you usually combine LIMIT with ORDER BY when selecting the top rows?", "answer": "Without an explicit order, the chosen rows are not guaranteed to be the same or to represent the intended top results." },
    { "question": "What does DISTINCT do in a SELECT list?", "answer": "It removes duplicate result rows from the selected columns or expressions." },
    { "question": "Why does `column = NULL` not test whether a SQL value is missing?", "answer": "NULL represents an unknown or absent value, so ordinary equality comparisons with it do not return true. Use `IS NULL` or `IS NOT NULL`." },
    { "question": "What is a primary key?", "answer": "A column or set of columns that uniquely identifies each row in a table; its values must be unique and not null." },
    { "question": "What is a foreign key used for?", "answer": "It constrains values in one table to refer to a key in another table, helping maintain relationships between records." },
    { "question": "What does COUNT(*) count?", "answer": "The number of rows in the input set, including rows whose individual columns contain NULL." },
    { "question": "What does GROUP BY do?", "answer": "It combines rows that share values in selected columns into groups, often so an aggregate can be calculated for each group." },
    { "question": "How does HAVING differ from WHERE?", "answer": "WHERE filters rows before grouping; HAVING filters groups after GROUP BY and can use aggregate results." },
    { "question": "What does an INNER JOIN return?", "answer": "Rows with matching join-condition values in both input tables." },
    { "question": "What does a LEFT JOIN return when a left-table row has no match on the right?", "answer": "It keeps the left row and fills the right table’s selected columns with NULL values." },
    { "question": "Why should a join condition usually compare related key columns?", "answer": "It pairs records that represent the same relationship, such as a student row with that student’s course-enrolment rows." },
    { "question": "Write a query that counts orders for each customer ID.", "answer": "SELECT customer_id, COUNT(*) FROM orders GROUP BY customer_id;" },
    { "question": "When is an aggregate filter such as `COUNT(*) > 3` placed in HAVING rather than WHERE?", "answer": "Use HAVING when the condition applies to the grouped count; WHERE cannot filter on an aggregate that has not yet been calculated." }
  ]
}
