eduard Posted April 17, 2011 Share Posted April 17, 2011 What do they mean by this? Link to comment Share on other sites More sharing options...
brainbug Posted April 17, 2011 Share Posted April 17, 2011 Please clarify your question a little more please. Link to comment Share on other sites More sharing options...
justsomeguy Posted April 17, 2011 Share Posted April 17, 2011 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 More sharing options...
eduard Posted April 17, 2011 Author Share Posted April 17, 2011 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 uOk, thanks! Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.