Jump to content

id as userid, fullname, userstatus (SELECT)?


eduard

Recommended Posts

If you're talking about AS, that's called an alias. You can make aliases for column names or table names. Sometimes two tables will have columns of the same name, so if you're using a JOIN in the SELECT then you would use AS to change their names:SELECT users.id AS user_id, posts.id AS post_id FROM users JOIN posts ON users.id=posts.userIn that example, the users and posts tables both have an ID column, so you need to use aliases to get them both. You can also use aliases for columns where the value comes from a function:SELECT COUNT(id) AS num_users FROM usersSELECT CONCAT(users.fname, ' ', users.lname) AS fullname FROM usersYou can also alias tables:SELECT u.id, u.fname, u.lname FROM users AS u

Link to comment
Share on other sites

If you're talking about AS, that's called an alias. You can make aliases for column names or table names. Sometimes two tables will have columns of the same name, so if you're using a JOIN in the SELECT then you would use AS to change their names:SELECT users.id AS user_id, posts.id AS post_id FROM users JOIN posts ON users.id=posts.userIn that example, the users and posts tables both have an ID column, so you need to use aliases to get them both. You can also use aliases for columns where the value comes from a function:SELECT COUNT(id) AS num_users FROM usersSELECT CONCAT(users.fname, ' ', users.lname) AS fullname FROM usersYou can also alias tables:SELECT u.id, u.fname, u.lname FROM users AS u
Ok, thanks!
Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...