0
Two "salary" colums?
Do Our table has now two colums with the same names 'salary'?
5 Answers
+ 2
No, you can't have 2 columns in an SQL database table that have the same names. You can't have 2 columns named "salary" in the same table.
If this is in reference to a mistake somewhere, share a link.
+ 1
torstenroggan wrote, "I think You are right Josh Greig ,)
I'm taking the SoloLearn SQL course.
We have the following table:
Colums: id, FirstName, LastName, Salary
The table is filled with several rows.
I thought, that with the command
SELECT id, FirstName, LastName , Salary+500 AS Salary FROM employees;
a *new* colum named Salary would be generated - but now, I think, I was wrong - wasn't I? "
Answer:
Yes, you're incorrect about a select adding a new column to the table.
That select reads data from the database without changing the data at all. That "Salary" that is returned by your select might make some reports easier to write but it won't affect the source data. The select is just a very flexible way to read data from the database and reformat the data for temporary use elsewhere without saving any changes back to the source.
Say you want to change the data to add 500 to everyone's salary.
Something like this should work even though I didn't test it:
update employees set salary = salary + 500;
Say you want to add a new column to the employees table called new_salary.
This adds the column but it'll initialize to null:
alter table employees add column new_salary int;
This initializes new_salary to be 500 more than salary:
update employees set new_salary = salary + 500;
0
... thanx a lot Josh Greig , but where is the new colums 'salary' stored in?
0
torstenroggan, are you referring to a course or article somewhere? It feels like you're assuming I have more context than I actually do.
If you had a salary in an SQL database, it would likely be a field in a database table. It could be a field in a table called Employees since salary is something that some employees have. Records or rows in the table would store the value of it.
If you can share whatever course or article is leading you to these salary questions, I can likely answer better.
0
I think You are right Josh Greig ,)
I'm taking the SoloLearn SQL course.
We have the following table:
Colums: id, FirstName, LastName, Salary
The table is filled with several rows.
I thought, that with the command
SELECT id, FirstName, LastName , Salary+500 AS Salary FROM employees;
a *new* colum named Salary would be generated - but now, I think, I was wrong - wasn't I? đŹ