Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialwafic fahme
3,309 Points5 tables query in access
I wrote the below because I want all the card_num that are of bin_name a and total_exp = 0. I look at it and I can see that it can be improved via Aliases... can anyone have a look at it and advise:
SELECT sep.card_num, oct.card_num, nov.card_num, dec.card_num, jan.card_num, feb.card_num
FROM(((( sep INNER JOIN oct ON sep.card_num = oct.card_num) INNER JOIN nov ON oct.card_num = nov.card_num) INNER JOIN dec ON nov.card_num = dec.card_num) INNER JOIN jan ON dec.card_num = jan.card_num) INNER JOIN feb ON jan.card_num = feb.card_num
WHERE sep.bin_name = 'a' OR oct.bin_name = 'a' OR nov.bin_name = 'a' OR dec.bin_name = 'a' OR jan.bin_name = 'a' OR feb.bin_name = 'a'
AND sep.total_exp = 0 AND oct.total_exp = 0 AND nov.total_exp = 0 AND dec.total_exp = 0 AND jan.total_exp = 0 AND feb.total_exp = 0
2 Answers
Steven Parker
231,248 PointsDo you mean table aliases, or column aliases?
Since your table names are already short and easily readable, I don't think table aliases would be an improvement. And column aliases can be easily assigned by changing the column names (but not the column source) in designer mode.
wafic fahme
3,309 PointsThank you, what I had in mind was how to alias the tables after the inner joins as one table and then to refer to this table in the WHERE clause rather than having to refer to every single table along with its column in the SELECT and WHERE statements.
Steven Parker
231,248 PointsTable aliases are assigned per table. It would not make sense to refer to all tables with a single name, because the columns you need to access all have similar names, and you need to identify the table names with the columns to avoid ambiguity.