Question:

Based on the following schema,
sailors (sailor-id, sailpr-name, age):
boats (boat-id, boat-name, colour):
reserves (sailor id, boat id, day);
Which of the following SQL queries returns all the ages of sailors whose names begin and end with ‘B’ and have at least three characters?

Show Hint

Use \texttt{LIKE} patterns with \texttt{\_} for a single character and \texttt{\%} for multiple characters. Combine them to enforce string length and structure.
Updated On: May 3, 2025
  • SELECT S.age FROM sailors S WHERE S.sailor_name LIKE 'B_\%B';
  • SELECT S.age FROM sailors WHERE S.sailor_name LIKE 'B_\%B';
  • SELECT S.age FROM sailors WHERE sailor_name AS CHAR >= 3;
  • SELECT S.age FROM sailors WHERE sailor_name AS MIN(CHAR) >= 3;
Hide Solution
collegedunia
Verified By Collegedunia

The Correct Option is A

Solution and Explanation

(A)

Goal:

Retrieve the age of sailors whose sailor_name:

  • (B) Starts with B
  • (C) Ends with B
  • (D) Has at least 3 characters

(E)

Pattern Breakdown:

The SQL pattern 'B_%B' means:

  • (F) B → First character
  • (G) _ → At least one middle character
  • (H) % → Any number of characters after that (including 0)
  • (I) B → Ends with B

So, this ensures a minimum of 3 characters with correct beginning and ending.

(J)

Option Analysis:

  • (K) Option A: Correct syntax and alias usage.
  • (L) Option B: Semantically same but no alias used — still valid, but Option A is cleaner.
  • (M) Option C & D: Incorrect SQL syntax for checking character length.
Was this answer helpful?
0
0

Top Questions on SQL

View More Questions