If I have two tables that have a column called direccion
, and I want to get only one of them, how do I do it?
Client table: ID, address, level, email, password, name
Company table: EID, address, name
What I want to do is:
SELECT ID, direccion, nivel FROM cliente, empresa WHERE ID = 1;
The result it gives me is that the column direccion
is ambiguous.
You alias the tables, and get the field you want from each table:
If you want only the value of the field of table1:
or if you want only the value of the field of table2:
Based on your question, if you wanted to get the address field only from the customer table it would be:
or otherwise:
I imagine that you mean to make a select of both tables but only show the field
direccion
of one of them. Use aliases and set which field you want to showThis is an example of how you can do it.
I think what you want to do is the following,
The way to do it is:
Aliases ARE NOT necessary, but they allow you to identify in the columns of the query which table each one belongs to, otherwise, it would show you: "Address" and you would not know which table it refers to.
I made the query on the Customer ID "AND" the EID of the company 2. If you do not put any EID of the company, it will throw you (in this way) ALL the addresses of the "company" table while it will always show you the same record of the "customer" table (the number 1).