EMP and DEPT sampledata query (SOLVED)
I don't have access to create tables at work - just to run selects on existing tables.
I've used the SQL below to use the 2 standard Oracle test dept and emp tables for testing, but - is it possible to use SQL to join the tables, or can the GET table WITH table AS ... SQL only ever work on one table at a time, rather than allowing joins to be done?
Thanks
GET dept
WITH dept AS
(SELECT 10 deptno
, 'ACCOUNTING ' dname
, 'NEW YORK' loc
FROM DUAL
UNION ALL
SELECT 20 deptno
, 'RESEARCH ' dname
, 'DALLAS' loc
FROM DUAL
UNION ALL
SELECT 30 deptno
, 'SALES ' dname
, 'CHICAGO' loc
FROM DUAL
UNION ALL
SELECT 40 deptno
, 'OPERATIONS ' dname
, 'BOSTON' loc
FROM DUAL)
SELECT *
FROM dept;
GET emp
WITH emp AS
(SELECT 7369 empno
, 'SMITH' ename
, 'CLERK' job
, 7902 mgr
, '17-Dec-80' hiredate
, 800 sal
, NULL comm
, 20 deptno
FROM DUAL
UNION ALL
SELECT 7499 empno
, 'ALLEN' ename
, 'SALESMAN' job
, 7698 mgr
, '20-Feb-81' hiredate
, 1600 sal
, 300 comm
, 30 deptno
FROM DUAL
UNION ALL
SELECT 7521 empno
, 'WARD' ename
, 'SALESMAN' job
, 7698 mgr
, '22-Feb-81' hiredate
, 1250 sal
, 500 comm
, 30 deptno
FROM DUAL
UNION ALL
SELECT 7566 empno
, 'JONES' ename
, 'MANAGER' job
, 7839 mgr
, '02-Apr-81' hiredate
, 2975 sal
, NULL comm
, 20 deptno
FROM DUAL
UNION ALL
SELECT 7654 empno
, 'MARTIN' ename
, 'SALESMAN' job
, 7698 mgr
, '28-Sep-81' hiredate
, 1250 sal
, 1400 comm
, 30 deptno
FROM DUAL
UNION ALL
SELECT 7698 empno
, 'BLAKE' ename
, 'MANAGER' job
, 7839 mgr
, '01-May-81' hiredate
, 2850 sal
, NULL comm
, 30 deptno
FROM DUAL
UNION ALL
SELECT 7782 empno
, 'CLARK' ename
, 'MANAGER' job
, 7839 mgr
, '09-Jun-81' hiredate
, 2450 sal
, NULL comm
, 10 deptno
FROM DUAL
UNION ALL
SELECT 7788 empno
, 'SCOTT' ename
, 'ANALYST' job
, 7566 mgr
, '19-Apr-87' hiredate
, 3000 sal
, NULL comm
, 20 deptno
FROM DUAL
UNION ALL
SELECT 7839 empno
, 'KING' ename
, 'PRESIDENT' job
, NULL mgr
, '17-Nov-81' hiredate
, 5000 sal
, NULL comm
, 10 deptno
FROM DUAL
UNION ALL
SELECT 7844 empno
, 'TURNER' ename
, 'SALESMAN' job
, 7698 mgr
, '08-Sep-81' hiredate
, 1500 sal
, NULL comm
, 30 deptno
FROM DUAL
UNION ALL
SELECT 7876 empno
, 'ADAMS' ename
, 'CLERK' job
, 7788 mgr
, '23-May-87' hiredate
, 1100 sal
, NULL comm
, 20 deptno
FROM DUAL
UNION ALL
SELECT 7900 empno
, 'JAMES' ename
, 'CLERK' job
, 7698 mgr
, '03-Dec-81' hiredate
, 950 sal
, NULL comm
, 30 deptno
FROM DUAL
UNION ALL
SELECT 7902 empno
, 'FORD' ename
, 'ANALYST' job
, 7566 mgr
, '03-Dec-81' hiredate
, 3000 sal
, NULL comm
, 20 deptno
FROM DUAL
UNION ALL
SELECT 7934 empno
, 'MILLER' ename
, 'CLERK' job
, 7782 mgr
, '23-Jan-82' hiredate
, 1300 sal
, NULL comm
, 10 deptno
FROM DUAL)
SELECT *
FROM emp;
is it you requirement.
WITH dept AS
(SELECT 10 deptno
, 'ACCOUNTING ' dname
, 'NEW YORK' loc
FROM DUAL
UNION ALL
SELECT 20 deptno
, 'RESEARCH ' dname
, 'DALLAS' loc
FROM DUAL
UNION ALL
SELECT 30 deptno
, 'SALES ' dname
, 'CHICAGO' loc
FROM DUAL
UNION ALL
SELECT 40 deptno
, 'OPERATIONS ' dname
, 'BOSTON' loc
FROM DUAL),
emp AS
(SELECT 7369 empno
, 'SMITH' ename
, 'CLERK' job
, 7902 mgr
, '17-Dec-80' hiredate
, 800 sal
, NULL comm
, 20 deptno
FROM DUAL
UNION ALL
SELECT 7499 empno
, 'ALLEN' ename
, 'SALESMAN' job
, 7698 mgr
, '20-Feb-81' hiredate
, 1600 sal
, 300 comm
, 30 deptno
FROM DUAL
UNION ALL
SELECT 7521 empno
, 'WARD' ename
, 'SALESMAN' job
, 7698 mgr
, '22-Feb-81' hiredate
, 1250 sal
, 500 comm
, 30 deptno
FROM DUAL
UNION ALL
SELECT 7566 empno
, 'JONES' ename
, 'MANAGER' job
, 7839 mgr
, '02-Apr-81' hiredate
, 2975 sal
, NULL comm
, 20 deptno
FROM DUAL
UNION ALL
SELECT 7654 empno
, 'MARTIN' ename
, 'SALESMAN' job
, 7698 mgr
, '28-Sep-81' hiredate
, 1250 sal
, 1400 comm
, 30 deptno
FROM DUAL
UNION ALL
SELECT 7698 empno
, 'BLAKE' ename
, 'MANAGER' job
, 7839 mgr
, '01-May-81' hiredate
, 2850 sal
, NULL comm
, 30 deptno
FROM DUAL
UNION ALL
SELECT 7782 empno
, 'CLARK' ename
, 'MANAGER' job
, 7839 mgr
, '09-Jun-81' hiredate
, 2450 sal
, NULL comm
, 10 deptno
FROM DUAL
UNION ALL
SELECT 7788 empno
, 'SCOTT' ename
, 'ANALYST' job
, 7566 mgr
, '19-Apr-87' hiredate
, 3000 sal
, NULL comm
, 20 deptno
FROM DUAL
UNION ALL
SELECT 7839 empno
, 'KING' ename
, 'PRESIDENT' job
, NULL mgr
, '17-Nov-81' hiredate
, 5000 sal
, NULL comm
, 10 deptno
FROM DUAL
UNION ALL
SELECT 7844 empno
, 'TURNER' ename
, 'SALESMAN' job
, 7698 mgr
, '08-Sep-81' hiredate
, 1500 sal
, NULL comm
, 30 deptno
FROM DUAL
UNION ALL
SELECT 7876 empno
, 'ADAMS' ename
, 'CLERK' job
, 7788 mgr
, '23-May-87' hiredate
, 1100 sal
, NULL comm
, 20 deptno
FROM DUAL
UNION ALL
SELECT 7900 empno
, 'JAMES' ename
, 'CLERK' job
, 7698 mgr
, '03-Dec-81' hiredate
, 950 sal
, NULL comm
, 30 deptno
FROM DUAL
UNION ALL
SELECT 7902 empno
, 'FORD' ename
, 'ANALYST' job
, 7566 mgr
, '03-Dec-81' hiredate
, 3000 sal
, NULL comm
, 20 deptno
FROM DUAL
UNION ALL
SELECT 7934 empno
, 'MILLER' ename
, 'CLERK' job
, 7782 mgr
, '23-Jan-82' hiredate
, 1300 sal
, NULL comm
, 10 deptno
FROM DUAL)
SELECT *
FROM emp,dept
where emp.deptno =dept.deptno
Similar Messages
-
How to get emp and dept tables of scott schema if they acdientally deleted
Hii I accedentally modifiled emp and dept tables in scott schema.... Can you please tell how to recreate fresh emp and dept tables ? is there any way to get emp and dept tables? please help regarding this
If you are on Oracle 10g version...
The demo tableds under scott schema can be created using oracle supplied script.
http://www.oracle.com/technology/sample_code/tech/sql_plus/htdocs/demobld.html
Alternatively, this script exists in $ORACLE_HOME/sqlplus/demo directory.
vr,
Sudhakar B. -
Emp and Dept table from JDeveloper tutorial
Hi all,
Under the tutorial for JDeveloper, I was going through the section 'Creating a Java Form Applet Using Wizard'. In one step, it asks to select 'Tables' - 'Emp' and 'Dept', but, the steps prior to that doesn't tell you how to add those tables in the database since I'm using my own database. Does anybody know where I can find the SQLScript to add these tables?
Regards,
ARThe samples are based on the EMP and DEPT tables, which are typically owned by Scott (password tiger). Check first to see if this user exists in the database (it is created automatically when you do a default database creation). Otherwise, you can find the script in ORACLE_HOME\rdbms\admin\scott.sql.
-- Brian -
Hi,
I believe that when the database is installed, a few tables are created which all users have access to, i.e. emp and dept.
Can anyone explain to me a bit more about where they are stored and particually where I can locate the scripts for these tables.
Cheers,
Nickrun $ORACLE_HOME\sqlplus\demo\demobld.sql as the user in which you want to install these test tables. Historically, this has been in the SCOTT schema.
HTH-Kevin -
Hi ,
I have mistakenly altered and dropped the Employee and Department Table.
Can anybody help me with the Structure and Data of these tables ?
Or provide me with a procedure to re-create the Emp and Dept table ?
Thanks,
NishaThank you very much !! That really helped.
You just have to execute that file.
For Eg in SQLPLUS : Just say ---> @D:\oracle\ora92\sqlplus\demo\demobld.sql -
Hi all,
11.2.0.1
I have departments in table DEPT which are 10 and 20. Department 10 has 100 employees in EMP while Department 20 has none in EMP, so it has no matching rows.
How can I create a query such that all dept with no EMP will be displayed:
DEPT EMP
==== ====
10 100
20 0
30 20
Thanks,
pKselect d.deptno
, (select count(*) from emp e where e.deptno = d.deptno) emps
from dept d;
-- or:
select *
from ( select d.deptno
, (select count(*) from emp e where e.deptno = d.deptno) emps
from dept d
where emps = 0; -
Data needed from emp and dept tables
Wondering if somebody can querry the emp table and dept table that comes with some versions of oracle already built in.
I need the data produced from these two querries
select * from emp
select * from deptIf you look in ORACLE_HOME/sqlplus/demo you'll find demobld.sql which contains the script the build all the scott tables.
-
in iMovie:
I open a project that has been finalized. source fragment is missing. I see a yellow triangle with exclamation mark. Why is that and how do I solve the problem?
please help.
J. AalbersShouldn't really be the MPE at fault here ... what is the codec of the footage/sequence/project?
Second, can you create a new project in PrPro, then in the media browser, import that sequence from the other project? -
My itunes library in my mac and mac book pro are not the same, depending on which machine I loaded the music on. Isn't icloud and match supposed to solve that problem?
wolverine76 wrote:
Isn't icloud and match supposed to solve that problem?
Um, not really. What are you trying to accomplish? -
When I click on Safari, I get the message "Safari quit unexpectedly." I know I have access to my wireless net work because I just found and downloaded updates and can send and receive mail. What is my problem and hoe is it solved?
As Outlook is not an Apple product, you will find more helpers familiar with Outlook here:
Office for Mac forums -
Since I updated my 4S iphone to the latest iOS7 version, I can no longer close any of my apps. As a result, all my apps remain open on my phone. Even powering down and restarting does not solve the problem. Specifically, when I double-click the start button, my open app icons display. But when I hold my finger on an icon, the apps do not wiggle and display an "x" to close. Any advice... thanks?!
Double tap the Home button, then swop upwards on the App Preview (not the App Icon). Tap the Home button again when done to return to normal screen.
-
Creation and transportation of query from development to simulation system
Hello experts,
I need to create a new Query in the development system in the General Ledger folder in Financial reporting. and then I need to transport the same to the simulation system. what are the correct steps I need to follow to do the same if have to avoid any issues during this transportation.
Do I need to do any modifications to the role ZS_XX_BEX_MENU and transport the same?
Could anyone help me in this regard giving me the exact procedure I need to follow.
RegardsNo need to modify, but if it is $temp then change it has ur won request.
follow the genral procedure
1)In RSA1 Go to Transport tab and collect ur query.
Drag to right screen
If it is in $Temp change it to your own request. For this You may need Access.
2)Query contains all objects which were used in that query.
if any Info object that are created newly then check for Transport
3) Then, finally click on transport(Truck) icon
4) By default, it will collect all new objects including newly created Info Objects also. You can change the collections of your own selection.
You will get a Request Number here. Please save this Number so that you can check this at SE09
5) In SE09 search for your Request Number.
6)Release The request by subsequent process onwards( Means sub contents like infoprovider first and then Query) -
I cannot shut dow my MacBook Pro using the apple icon (as it was suppose to be), actually I have to press and hold the on/off buttom. I have taken twice for Mac dealer and they did not solve the problem. What must I do? I would to remark that I have installed 2 antivirus and uninstalled one of them. Since then I have facing this troublesome issue. Thanks
Uninstall the other AV software. They are not needed. All they do is cause trouble like you are having now.
If you have been forcing the Mac to shut down with the power switch you may nave corrupted your disk. You should repair it with disk Utilty to remove any corruption the shutdwons may have cased.
Allan -
I tried to import a PDF of a line drawing into Photoshop Elements. The thumbnail looks fine, but when imported the file is empty. This used to work in the past. What is wrong and how do I solve this?
Hi
The value of the Channel Strip volume etc is not stored within the C Strip setting, as you have discovered.
If you really wanted, you could add a Gain plug to the strip, with it set to give the correct output level with the Fader set to 0
(Or just set the fader manually in MS)
CCT -
I get a message that my iPad is running an unauthorized modified version, even though I'm currently running 4.3.3. What does it mean, and how can I solve this problem? Please help, i ve tried everything. Thanks
I bought my iPad 2 three months ago from apple, and all my updates re from apple through iTunes. Version 4.3.3 is the latest version I updated, have been trying hard to update 4.35 but I get error messages all the time when the update is almost complete. Everything was working beautifully since I bought it, but this update problem just cropped up last week. I need a way out pls.
Maybe you are looking for
-
Adobe is giving me the runaround when all i want to do is download the programs i bought several years ago. Anyone else experience this? Contacted support, was told i would get a call back. Account blocked so I had to create a new one to download tr
-
HP Pavilion g7 Notebook PC WITH Windows 7 one month old. Control key sticks, have to reboot to clear. any solutions?
-
Send Meeting requests in a calendar format with alerts/reminders?
To be able to set up Meetings that will automatically notify invited attendees.
-
when i take a call or dial a call in the high density traffic area or noicy area i can't hear properly so at that time i put my phone in the loud speaker mode.
-
Migration of Oracle9iAS Portal across DB's
Hi: I tried to migrate my portal 3.0.9.8.3 repository that's in 9.0.1.4 database on Windows to an 9.0.1.4 database on Linux following the instruction in "Migration of Oracle9i Application Server Portal (Release 1) Across Databases" An Oracle White Pa