开发者

MySQL query alias?

I was reading something a few months ago that would take something like:

SELECT first, last FROM contacts where status = 'active'

and turn it into:

SELECT first, last FROM active_contacts

It's definitely not a stored procedure and I'm pretty sure it's not a prepared statement. I'm also positive what I was readin开发者_如何学编程g did not involve temporary tables or anything like that. It was something that didn't modify or move the data in any way.

Thanks in advance!


You are talking about views.

You can create a view as:

CREATE VIEW  active_contacts AS 
SELECT first, last 
FROM contacts 
WHERE status = 'active'

then use it as:

SELECT first, last FROM active_contacts


I think it must be view. The view would be defined in terms of a query, in this case:

SELECT * from contacts where status = 'active'

The view is given a name active_contacts and can be referenced by this name as if it were a table.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜