Moeb
Moeb

Reputation: 10871

How to create an MySQL query alias?

For example I use this

select * from tab1;

every 5 minutes.

Is there a way to set up an alias p so that I can just do

p

instead and that query is executed?

Upvotes: 3

Views: 697

Answers (4)

Daniel Vassallo
Daniel Vassallo

Reputation: 344561

You may want to use a stored procedure. You could call it by using:

CALL p;

This is how to create a stored procedure for the example in your question:

CREATE PROCEDURE p() SELECT * FROM tab1;

Upvotes: 1

Michael Pakhantsov
Michael Pakhantsov

Reputation: 25390

Create stored procedure p with your query

and type

   call p

Upvotes: 0

Dennis Haarbrink
Dennis Haarbrink

Reputation: 3760

This calls for a view, but in your case it isn't much shorter: create view p as selecT * From tab1;
You'd use it as: select * from p

It does get more interesting with more complex queries though.

Upvotes: 3

Daniel Egeberg
Daniel Egeberg

Reputation: 8382

You can create a stored procedure and then call it like CALL p.

http://dev.mysql.com/doc/refman/5.1/en/stored-routines.html

Upvotes: 2

Related Questions