0% found this document useful (0 votes)
6 views3 pages

DBMS

Dbms note
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views3 pages

DBMS

Dbms note
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

DBMS LAB

1.1 Query to display Employee Name, Job, Hire Date, Employee


Number; for each employee
with the Employee Number appearing first.
ANS:

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:

 empno: This represents the Employee Number.


 ename: This represents the Employee Name.
 job: This represents the Job of the employee.
 hiredate: This represents the Hire Date of the employee.

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.

1.2Query to display unique Jobs from the Employee Table.


To display the unique jobs from the Employee table, you can use the SELECT DISTINCT
statement in SQL. The DISTINCT keyword ensures that only unique values are returned in the
result set.
Here’s the query:

SELECT DISTINCT job


FROM emp;
OUTPUT:

 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.

For example, if your table has the following job titles:

Manager

Clerk

Analyst

Clerk

Manager

The query will return:

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.

For MySQL or PostgreSQL:

In MySQL or PostgreSQL, you can use the CONCAT function or the || operator for concatenation.
Here’s how you can do it:

SELECT CONCAT(ename, ', ', job) AS "Employee_Info"


FROM emp;

For SQL Server:

In SQL Server, you use the + operator for concatenation:

SELECT ename + ', ' + job AS "Employee_Info"

FROM emp;

For Oracle:

In Oracle, you also use the || operator for concatenation:

SELECT ename || ', ' || job AS "Employee_Info"

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:

Assuming your table emp has the following data:

ename job
John Manager
Jane Clerk
Smith Analyst

The query will return:

Employee_Info
John, Manager
Jane, Clerk
Smith, Analyst

This output lists each employee’s name concatenated with their job title, separated by a comma.

You might also like