Issue
I am using mysql server for sql.
Select * from products some_garbage_value;
and
Select * from products;
resulting the same value. Why?
Entering anything at the place of some_garbage_value, still result the same query result.
I have created a form to enter query and that form is handled by a servlet and after creating a connection, i am resulting the query result on that servlet.
Is this bad thing for my form, if yes then tell me, How to get rid of this bug? Is this a bug? Can it be a case of SQL Injection?
Solution
In
Select * from products some_garbage_value;
The some_garbage_value
is not garbage, it is an alias. Technically this means that for the scope of query, you have 'renamed' this occurrence of the products
table to some_garbage_value
. This can be very useful if you need to disambiguate between two occurrence of the same table (eg in self-join), or to make your query more readable/self-explanatory (or just shorter).
It is equivalent to
Select * from products as some_garbage_value;
See also the MySQL reference for select
:
The
FROM table_references
clause indicates the table or tables from which to retrieve rows. If you name more than one table, you are performing a join. For information on join syntax, see Section 13.2.9.2, “JOIN Syntax”. For each table specified, you can optionally specify an alias.tbl_name [[AS] alias] [index_hint]
This wouldn't work with just any value: it must be a syntactically valid identifier.
Answered By - Mark Rotteveel