# Miscellaneous > Ask an Expert >  SQL query help foreign key

## ynottony

Hi,

I have tried to look for help on this on the net but can't find any.
I got a table that looks like this

tableA.uid_code       tableA.str_code           tableA.str.name            tableA.uid_r_code (this links to uid.code)
1                                  A                           Apple                              2 
2                                  B                           Banana                            1 
3                                  C                            Cat                                1

How do I do a SELECT query to get all the columns above but for tableA.uid_r_code instead of showing 2,1 and 1, show the str_name that is linked to it, so show Banana, Apple and Apply?

Thanks

----------


## ynottony

sorry the top didn't appear correctly



```
tableA.uid_code tableA.str_code tableA.str.name tableA.uid_r_code (this links to uid code)
1               A               Apple           2
2               B               Banana          1
3               C               Cat             1
```

----------


## rmiao

Is tableA a table name? All columns are in same table? Which rdbs do you use?

----------


## ynottony

> Is tableA a table name? All columns are in same table? Which rdbs do you use?


yes, tableA is a table

All columns with are within the same table

SQL DB?

----------


## rmiao

Why need fkey that references the column in same table?

----------


## rmiao

For sql server db, you can't have '.' in column name without [ ] surrounded.

----------


## ynottony

> Why need fkey that references the column in same table?


I'm not sure, i didn't create the database

----------


## ynottony

> For sql server db, you can't have '.' in column name without [ ] surrounded.


opps...yeah I supposed to type in TableA.str_name instead of a '.' in the middle

----------


## SpywareDr

Microsoft Developer Network > Characters that are not allowed in table name & column name in sql server ?


> The Common rules:
> *Rules for Regular Identifiers*
> 
> The rules for the format of regular identifiers depend on the database compatibility level. This level can be set by using ALTER DATABASE. When the compatibility level is *100*, the following rules apply:
> 
> The first character must be one of the following:
> 
> A letter as defined by the Unicode Standard 3.2. The Unicode definition of letters includes Latin characters from a through z, from A through Z, and also letter characters from other languages.
> The underscore (_), at sign (@), or number sign (#).
> ...

----------

