SQLTeam.com | Weblogs | Forums

I am trying to SELECT from 2 tables WHERE is same name

I am creating database . I am trying to find 2 columns with same name Jan I got 2 Tablets:

Table 1 :

CREATE TABLE Zamestnanci
(
id_Zamestnanca int not null,
Meno varchar(50) null,
Priezvisko varchar(50)null,
Adresa varchar(50) null,
Datum_narodenia date null,

PRIMARY KEY (id_Zamestnanca)

);*

Table 2 :
*
CREATE TABLE ObčaniaSR
(
id_Občana int not null,
Meno varchar(50) null,
Priezvisko varchar(50) null,
Adresa varchar(50) null,
Datum_narodenia date null,
Zápis_v_trestnom_registry varchar(50) null,

PRIMARY KEY (id_Občana)

);*

I created querry :
SELECT Zamestnanci.Meno, ObčaniaSR.Meno
FROM Zamestnanci
JOIN ObčaniaSR
ON Zamestnanci.Meno = ObčaniaSR.Meno
Where Zamestnanci.Meno AND ObčaniaSR.Meno = 'Ján';

What AM I doing wrong Thank you for your answers and advices.

What is the error. your WHERE clause for Meno needs a value.

WHERE Zamestnanci.Meno = ??? what
Where Zamestnanci.Meno AND ObčaniaSR.Meno = 'Ján';

I got this error Msg 209, Level 16, State 1, Line 7
Ambiguous column name 'Meno'.

you need to specify the alias for wherever you are using Memo elsewhere.
since this is a school project, I dont think you are learning really, just hacking away and asking without understanding.

I encourage you to understand why first. instead of just copying and doing what others recommend without understanding.

1 Like

I made it run but it return column name Meno instead of value Jan. Any suggestions?