I've got a table with a list of employees names, their employee ID and their salary.
I'd like to update the salary for one of the employees (Stacy) from 73000 to 90000 - see sample data below:
employee_id first_name salary
2009 Stacy 73000
I was thinking of writing something like this:
update salary from employees where first_name = 'stacy'
But does any how where I should incorporate the updated salary?
The table is called 'employees' and the field I'd like to update is the salary field.
TIA
UPDATE employees SET salary = 90000 WHERE first_name = 'stacy'
Related
I have a table with 2 columns and 9 Rows, FirstName and LastName.
All rows of FirstName Column IS NOT NULL, but 1 row of LastName is NULL.
How would I put a value into NULL?
This is the Code I have:
SELECT Emp1.FirstName Employee, Emp2.FirstName Manager
FROM Employee Emp1
LEFT JOIN Employee Emp2 ON Emp2.EmployeeID = Emp1.ReportsTo;
Which produces:
I have tried IFNULL, but it didn't seem to work.
SELECT Emp1.FirstName Employee, Emp2.FirstName Manager, IFNULL('No Manager')
FROM Employee Emp1
LEFT JOIN Employee Emp2 ON Emp2.EmployeeID = Emp1.ReportsTo;
The syntax for ISNULL is slightly different. Try this:
SELECT Emp1.FirstName Employee, IFNULL(Emp2.FirstName, 'No Manager') as Manager
FROM Employee Emp1
LEFT JOIN Employee Emp2 ON Emp2.EmployeeID = Emp1.ReportsTo;
Please let me know if I can help you further.
I have employee table which have employee id as int, employee name as string and department id as array of integer data type as the columns. Give below are the records for the Employee table.
employee5.empid employee5.empname employee5.deptid
1 Emp1 [2,3,1,4]
2 Emp2 [5,2,3,4]
3 Emp3 [1,4,2,3]
4 Emp4 [5,3,4,1]
5 Emp5 [1,2,3,4]
6 Emp6 [5,3,1,2]
7 Emp7 [3,2,4,5]
8 Emp8 [1,4,2,3]
9 Emp9 [5,2,3,1]
10 Emp10 [2,4,3,5]
I also have the department table which have department id as int, department name as string and department location as string columns. Give below are the records for the department table.
department.deptid department.deptname department.location
1 IT Delhi
2 Support Bangalore
3 HR Pune
4 Finance Mumbai
5 Call Center Mysore
As I am new to the hive, please help me in displaying the employee name and his corresponding department using the hive join.Thanks in advance.
I haven't tested however, this is might work.
First, you need to explode the array into multiple rows and then need the join, I don't think is a direct way to join.
select * from
(select empid, empname, dept_id from employee5 lateral view explode(deptid) d as dept_id) emp
join
department
on
department. deptid = emp.dept_id
When I type & execute this query in PL/SQL Developer:
select employee_id, first_name, last_name, job_id, &column_name
from employees WHERE &condition ORDER BY &order_column
I got the error message:
ORA-00936:missing expression.
Although when I execute this query, variables field prompt up on my screen with three field names respectively column_name, condition and order_column.
After entering the values in the above three fields respectively-- salary, >10000, employee/-id When I click ok, I get the above mentioned error message.
Can anyone please help to sort out this issue?
If you try to run your query in SQLPlus, it will show you how your query is transformed by the usage of the values you give to the variables:
SQL> select employee_id, first_name, last_name, job_id, &column_name from employees WHERE &condition ORDER BY &order_column;
Enter value for column_name: salary
Enter value for condition: >1000
Enter value for order_column: employee/-id
old 1: select employee_id, first_name, last_name, job_id, &column_name from employees WHERE &condition ORDER BY &order_column
new 1: select employee_id, first_name, last_name, job_id, salary from employees WHERE >1000 ORDER BY employee/-id
select employee_id, first_name, last_name, job_id, salary from employees WHERE >1000 ORDER BY employee/-id
*
ERROR at line 1:
ORA-00936: missing expression
So, your query becomes the following:
select employee_id, first_name, last_name, job_id, salary from employees
WHERE >1000 ORDER BY employee/-id
which is obviously wrong.
You need to give a well format condition ( for example salary > 1000) and to use the right column identifiers for the ORDER BY clause ( say employee_id); for example:
SQL> select employee_id, first_name, last_name, job_id, &column_name from employees WHERE &condition ORDER BY &order_column;
Enter value for column_name: salary
Enter value for condition: salary > 10000
Enter value for order_column: employee_id
old 1: select employee_id, first_name, last_name, job_id, &column_name from employees WHERE &condition ORDER BY &order_column
new 1: select employee_id, first_name, last_name, job_id, salary from employees WHERE salary > 10000 ORDER BY employee_id
EMPLOYEE_ID FIRST_NAME LAST_NAME JOB_ID SALARY
----------- -------------------- ------------------------- ---------- ----------
100 Steven King AD_PRES 24000
101 Neena Kochhar AD_VP 17000
...
15 rows selected.
SQL>
Is that your column name? employee/-id? That may be part of your problem here.
Basically using anything different than:
Alphabets
Numbers (not at start of the column name)
Underscore (_)
is not recommended as it is not a good way to name fields and some datasources might throw errors on other characters.
For some reason, sqlite3 is not matching rows that have a NULL value for a query that clearly should match it.
Say I have an employees table with two columns name and salary that has the following data:
sqlite> SELECT * FROM employees;
id name salary
--------------- --------------- ---------------
1 John Smith 10000
2 Mary Anderson 20000
3 David White NULL
Executing the following query results in:
sqlite> SELECT * FROM employees WHERE salary NOT IN (10000);
id name salary
--------------- --------------- ---------------
2 Mary Anderson 20000
Shouldn't I also expect row with id=3 to be in the list? Why isn't it on the list? I've been able to confirm this behavior in sqlfiddle.
You can't compare NULL to anything. There are IS NULL and IS NOT NULL operators in SQL to deal with it.
The proper query would be
SELECT *
FROM employees
WHERE salary NOT IN(50000)
OR salary IS NULL;
Here is SQLFiddle demo
i have an dataset with 3 tables in it they have a masterchild relationship,
lets say the dataset is like this
department table
deptID departmentname
1 IT
2 CS
3 EC
employee table
empID Empname DeptID
1 kiran 1
2 manu 2
3 kumar 3
4 ajay 3
now i have to delete value deptID =3 from department table
then all the employee who have DeptID ='3' have to be deleted from Employee table
how do we do in dataset , is there any builtin function
thanks
Prince5
You have to define a ForeignKeyConstraint and set the rule to cascade:
ForeignKeyConstraint fk = new ForeignKeyConstraint(dtDepartment.Columns["deptID"], dtEmployee.Columns["DeptID"]);
fk.DeleteRule = Rule.Cascade;
Now when you delete records in the parent it will delete them in the children as well.
You can add a constraint to you dataset and enable cascade deleting
http://msdn.microsoft.com/en-us/library/st1t2c35.aspx