Hi shozza87,
No its not a stupid question 🙂
Well Actually those As and Bs are called table alias. Well its doesn`t have to be A or B it can be any thing... simply we use alias in our queries because it makes a query easy to read and write.
we can write the same query as,
SELECT competitions.compid, competitions.compname, competitions.comptype FROM competitions LEFT JOIN entercomp ON competitions.compid = entercomp.compid where entercomp.Teamid=1
which one is easy to write?🙂 query with alias right?
One important thing about using alias is that assume your querying two tables which has same column names but different values and you want records from both tables. In this case we have to use alias values to tell the database engine that we need data from both tables which has same field name.
Here is a small example:
products
id
name
comment
product_comments
id
productId
comment
now if you want the product with their comments you have to use alias when querying the tables because as you can see comment field is present in both tables.
so simple query will be,
SELECT A.id, A.name, B.comment FROM products A LEFT JOIN product_comments B ON B.productId = A.id AND A.id = <-- product id -->
Hope this clear your doubts.
Please read more about joins since that will reduce the no of queries you have to use to achieve something.
best regards,
niroshan