Vidyalelo
MySQL · Q896

MySQL

Programming · MySQL · question 896

Q896

Which of the following MySQL statements is valid if '`sampledb`' is a database and '`tbl`' is a table in it?

A.
SELECT * FROM `sampledb.member`
B.
SELECT * FROM `sampledb`.`member`
Answer
C.
SELECT * FROM `member`.`sampledb`
D.
SELECT * FROM `member.sampledb`

Answer: Option B

Solution

Answer: Option B
Solution:
This question is about how to correctly reference a table within a database in MySQL. Imagine you have a bookshelf (`sampledb`) and a book (`tbl`) on it. We need to tell MySQL where to find that book.

Let's look at each option:
Option A: SELECT * FROM `sampledb.member` - This is incorrect. The format is confusing and MySQL won't understand where to find the `member` table.
Option B: SELECT * FROM `sampledb`.`member` - This is the correct way to reference the table. It tells MySQL to look for the `member` table inside the `sampledb` database.
Option C: SELECT * FROM `member`.`sampledb` - This is wrong. It's like putting the book name first and then the bookshelf name, which doesn't make sense.
Option D: SELECT * FROM `member.sampledb` - Similar to Option A, this format is also incorrect. MySQL won't understand this reference.

Therefore, the only valid statement is Option B: SELECT * FROM `sampledb`.`member`.