0
why FROM if table name is specified
I was wondering why need to specify FROM table if we already declared it before id?
3 Answers
+ 6
Uchiha I supposed you refer to SQL sentence right? for example
SELECT name FROM students;
Obviously this is syntax for SQL but if you have two tables with a colum "name" each one, then, how could you do to get "name" from one specifically? with name of table.
Example:
Table1: Student
Field1: ID
Field2: Name
Field3: Phone
Field4: Age
Field5: Email
Table2: Teacher
Field1: ID
Field2: Name
Field3: Phone
Field4: Car
Field5: Address
So in that case, you must to know what information do you want
SELECT Name FROM Student;
You will show names of all students.
SELECT Name FROM Teacher;
You will show names of all teachers.
I will be hope you understand or maybe, if you have other problem or question, please, explain.
+ 5
Ahh ok. That sintax is correct but you can use your query in this other way:
"SELECT username FROM users"
Other sintax are with my examples:
SELECT Student.Name, Student.Phone, Teacher.Name, Teacher.Phone FROM Student, Teacher;
With alias:
SELECT S.Name, S.Phone, T.Name, T.Phone FROM Student as S, Teacher as T;
0
Daniel I appreciate the effort you put in your answer.
I Guess a proper yet rude answer can be
*because that's how the syntax works*.
What I was really asking was why use
"SELECT users.username
from users"
(when you already specified the table next to username in the first line)
Thanks again.