When querying a database in SQLite I find it useful to give alias to the tables I am working with. It also helps resolve naming conflicts.
SELECT a._id, a.name, b.email FROM people AS a, emails AS b
However then when I look for the columns "_id", "name", and "email" in my cursor, I get an error that the columns cannot be found. It only works if I change the query to:
SELECT a._id AS "_id", a.name AS "name", b.email AS "email" FROM people AS a, emails AS b
Is there a way to get the base column name without the extra work?
Declaring an alias to a column is a better way to avoid errors. The two tables the your querying may have the same column names and it can be difficult to differentiate them without aliases. The only way to differentiate them is by associating them with their table names or giving them aliases.
Aliases can make queries easier to both write and to read. You can give a table or a column another name by using an alias. This can be a good thing to do if you have very long or complex table names or column names
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With