I\'m new in this comunnity and I need to work with a query that get data from a mysql database, I have this query, but I need to add a new table and I don\'t understand why the
In MySQL, an "alias" can be declared to simplify the query later. Typically this is denoted with the "AS" operator, but can also be declared without "AS" - as in your example.
In your example:
SELECT ins.matricula, {...}
FROM Inscripciones ins {...}
The ins
is set as an alias for the "Inscripciones" table.
This allows you to use ins
throughout the query rather than typing out "Inscripciones." This can be seen in the SELECT
statement.
Something to keep in mind - aliases in SQL can be declared after they're first used. This is the case in your example, where SELECT
gets ins.matricula
before you've actually declared ins
as the alias for Inscripciones
.
Sometimes this seems counter intuitive, but I promise it will make sense if you experiment with it a bit.
I find it less ambiguous to include the "AS" - which might help it make more sense as you're reading/writing the SQL query.
ex: ... FROM Inscripciones AS ins
To be clear, the use of the alias doesn't change the outcome of your query, but helps you write cleaner queries because you don't have to re-write the tablename every time you want to use it.