DBMS
DBMS
To display the Employee Name, Job, Hire Date, and Employee Number for each employee, with the
Employee Number appearing first, you would use a SQL query similar to the following:
SELECT empno AS "Employee Number", ename AS "Employee Name", job AS "Job", hiredate AS "Hire
Date"
FROM emp;
OUTPUT:
Example Query:
Assuming your table name is emp, the query to display the desired information with Employee
Number appearing first would be as shown above.
This will output a table with columns titled "Employee Number", "Employee Name", "Job", and
"Hire Date". The columns will appear in the order you specified, with the employee number
listed first.
SELECT DISTINCT job: This part of the query selects the unique job titles from the emp
table.
FROM emp: This specifies the table from which to retrieve the data.
Example Result:
If your Employee table (emp) has multiple employees with the same job title, this query will
return each job title only once.
Manager
Clerk
Analyst
Clerk
Manager
Manager
Clerk
Analyst
1.3 Query
to display the Employee Name concatenated by a Job
separated by a comma
ANS:
To display the Employee Name concatenated with the Job, separated by a comma, you can use
the CONCAT function in SQL. Depending on the SQL database system you are using, the syntax
for concatenation might differ slightly.
In MySQL or PostgreSQL, you can use the CONCAT function or the || operator for concatenation.
Here’s how you can do it:
FROM emp;
For Oracle:
FROM emp;
OUTPUT:
CONCAT(ename, ', ', job) or ename + ', ' + job or ename || ', ' || job:
Concatenates the Employee Name (ename) and Job (job), separated by a comma and a
space.
AS "Employee_Info": Provides an alias for the resulting column to be labeled as
"Employee_Info".
Example:
ename job
John Manager
Jane Clerk
Smith Analyst
Employee_Info
John, Manager
Jane, Clerk
Smith, Analyst
This output lists each employee’s name concatenated with their job title, separated by a comma.