Aliases in SQL (1 Viewer)

jaryszek

Registered User.
Local time
Today, 08:43
Joined
Aug 25, 2016
Messages
756
Hi,

i have sql like here:

Code:
SELECT qryIm_Temp_SystemVersionsNMtblSystemVersions3.*, tblSystemVersions.SystemVersionID
FROM qryIm_Temp_SystemVersionsNMtblSystemVersions3 INNER JOIN tblSystemVersions ON (qryIm_Temp_SystemVersionsNMtblSystemVersions3.VersionName = tblSystemVersions.VersionName) 
AND (qryIm_Temp_SystemVersionsNMtblSystemVersions3.BundleID = tblSystemVersions.BundleID) AND (qryIm_Temp_SystemVersionsNMtblSystemVersions3.Function = tblSystemVersions.Function) AND (qryIm_Temp_SystemVersionsNMtblSystemVersions3.VersionID = tblSystemVersions.VersionID);

where can i use aliases for tables?

please help,
Jacek
 

Minty

AWF VIP
Local time
Today, 16:43
Joined
Jul 26, 2013
Messages
10,368
Intead of
FROM qryIm_Temp_SystemVersionsNMtblSystemVersionq3
Use
FROM qryIm_Temp_SystemVersionsNMtblSystemVersions3 Q3 <--- The Alias
Then
Select q3.* etc etc


Edited the Typo !
 
Last edited:

jaryszek

Registered User.
Local time
Today, 08:43
Joined
Aug 25, 2016
Messages
756

Attachments

  • Screenshot_9.jpg
    Screenshot_9.jpg
    43 KB · Views: 78

Minty

AWF VIP
Local time
Today, 16:43
Joined
Jul 26, 2013
Messages
10,368
Sorry typo that should be

Q3.*

Table then field reference , doh must be a Friday...
 

theDBguy

I’m here to help
Staff member
Local time
Today, 08:43
Joined
Oct 29, 2018
Messages
21,457
Hi Jacek. When you assign an alias to a table, you’ll have to use the alias in place of the table name everywhere in your query. You can’t use a mixed syntax.
 

rpeare

Registered User.
Local time
Today, 08:43
Joined
Sep 15, 2016
Messages
18
Also, you don't use AS when you alias your table, only your field names

Select TESTFIELD as OMGTEST
from qryIm_Temp_SystemVersionsNMtblSystemVersions3 Q3

TESTFIELD is aliased to OMGTEST
qryIm_Temp_SystemVersionsNMtblSystemVersions3 is aliased to Q3
 

jaryszek

Registered User.
Local time
Today, 08:43
Joined
Aug 25, 2016
Messages
756
oo thank you, Very nice to know this.

I will test approach.

Best,
Jacek
 

theDBguy

I’m here to help
Staff member
Local time
Today, 08:43
Joined
Oct 29, 2018
Messages
21,457
oo thank you, Very nice to know this.

I will test approach.

Best,
Jacek
Hi. Just FYI. I think the AS part is optional. You don't have to use it, but it doesn't mean you can't. Cheers!
 

jaryszek

Registered User.
Local time
Today, 08:43
Joined
Aug 25, 2016
Messages
756
hmm still this is not working:



Jacek
 

Attachments

  • Screenshot_10.jpg
    Screenshot_10.jpg
    85.9 KB · Views: 94

theDBguy

I’m here to help
Staff member
Local time
Today, 08:43
Joined
Oct 29, 2018
Messages
21,457
hmm still this is not working:

Jacek
Hi Jacek. Did you see my comment earlier. You'll have to use the alias everywhere, once you assigned it. For example:
Code:
SELECT [COLOR=red]Q3[/COLOR].*
FROM Query1 AS [COLOR=Red]Q3[/COLOR]
INNER JOIN Query2
 ON [COLOR=red]Q3[/COLOR].FieldName=Query2.FieldName
WHERE [COLOR=Red]Q3[/COLOR].FieldName=SomeValue
 

Users who are viewing this thread

Top Bottom