Jump to content

id as userid, fullname, userstatus (SELECT)?


eduard
 Share

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

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...