File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -275,4 +275,86 @@ DROP TABLE employees;
275275```
276276
277277---
278+ ## 31. What is the difference between SERIAL and BIGSERIAL?
279+ ** Answer:**
280+ SERIAL: Auto-incrementing integer (4 bytes), range up to ~ 2 billion.
281+ BIGSERIAL: Auto-incrementing big integer (8 bytes), range up to ~ 9 quintillion.
282+
283+ ---
284+ ## 32. How do you create a foreign key?
285+ ** Answer:**
286+ ``` sql
287+ CREATE TABLE orders (
288+ id SERIAL PRIMARY KEY ,
289+ customer_id INT REFERENCES customers(id),
290+ order_date DATE
291+ );
292+ ```
293+
294+ ---
295+ ## 33. How do you limit the number of rows returned?
296+ ** Answer:**
297+ ``` sql
298+ SELECT * FROM employees LIMIT 5 ;
299+ ```
300+
301+ ---
302+ ## 34. How do you skip rows using OFFSET?
303+ ** Answer:**
304+ ``` sql
305+ SELECT * FROM employees
306+ LIMIT 5 OFFSET 10 ;
307+ ```
308+
309+ ---
310+ ## 35. How do you combine results from two queries?
311+ ** Answer:**
312+ ``` sql
313+ SELECT name FROM employees
314+ UNION
315+ SELECT name FROM managers;
316+ ```
317+
318+ ---
319+ ## 36. How do you check the structure of a table?
320+ ** Answer:**
321+ ``` sql
322+ \d employees
323+ ```
324+
325+ ---
326+ ## 37. How do you find the current database?
327+ ** Answer:**
328+ ``` sql
329+ SELECT current_database();
330+ ```
331+
332+ ---
333+ ## 38. How do you find the current user?
334+ ** Answer:**
335+ ``` sql
336+ SELECT current_user ;
337+ ```
338+
339+ ---
340+ ## 39. How do you concatenate strings?
341+ ** Answer:**
342+ ``` sql
343+ SELECT first_name || ' ' || last_name AS full_name
344+ FROM employees;
345+ ```
346+
347+ ---
348+ ## 40. How do you use CASE statements in queries?
349+ ** Answer:**
350+ ``` sql
351+ SELECT name,
352+ CASE
353+ WHEN age < 30 THEN ' Young'
354+ ELSE ' Experienced'
355+ END AS age_group
356+ FROM employees;
357+ ```
358+
359+ ---
278360
You can’t perform that action at this time.
0 commit comments