Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 380
Moeb Avatar asked Dec 18 '25 08:12

Moeb


2 Answers

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.

like image 57
Dennis Haarbrink Avatar answered Dec 21 '25 05:12

Dennis Haarbrink


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

like image 28
Daniel Egeberg Avatar answered Dec 21 '25 05:12

Daniel Egeberg



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!