Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

Databases

wafic fahme
wafic fahme
3,309 Points

5 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
Steven Parker
220,450 Points

Do 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
wafic fahme
3,309 Points

Thank 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
Steven Parker
220,450 Points

Table 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.