SQL Help - Using Minus command
Hey Sql forum
I'm using ver: Oracle 8.1.7.0.0
Quick Question for all of you.
I'm trying to run this query.
When I add my order by on each select statement the query doesn't work.
But when I remove the two order by statements on each query it works just fine.
Why is that?
Please get back to me thanks.
Query:
select
b.em_employee_id,
b.tcf_date_worked,
b.tcf_hours,
b.tcf_pdt_code,
b.tcf_payroll_unit
from tcf b
where b.tcf_year = '2006' and b.tcf_run_id in ('XXXX')
order by b.em_employee_id, b.tcf_date_worked, b.tcf_pdt_code, b.tcf_hours
minus
select
a.em_employee_id,
a.tcfa_date_worked,
a.tcfa_hours,
a.tcfa_pdt_code,
a.tcfa_payroll_unit
from tcfa a
where a.tcfa_year = '2006' and a.tcfa_run in ('1234')
order by a.em_employee_id, a.tcfa_date_worked, a.tcfa_pdt_code, a.tcfa_hours ;
}
Using the positional notation (1,2,3...) is often frowned upon because a change in the order of the columns in your select lists will cause the query to be sorted differently.
The other option is to use the appropriate column aliases so that the column names from both queries "line up". Then use the aliases in your order by.
SQL> select deptno dno, dname dnm
2 from dept
3 union all
4 select deptno dno, dname dnm
5 from dept
6 order by dnm, dno;
DNO DNM
10 ACCOUNTING
10 ACCOUNTING
40 OPERATIONS
40 OPERATIONS
20 RESEARCH
20 RESEARCH
30 SALES
30 SALES
8 rows selected.(used dept instead of dual)
Message was edited by:
Eric H
Similar Messages
-
Calling SQL Loader using HOST command from Developer Forms 4.5
I want to execute a set of code from D2K Forms 4.5 which has interfface with Client - OS ( In my case Windows NT/XP). I want to execute SQL Loader from Forms using Host Command and then after completion of that process, I want to do next transcations ( depending upond success of HOST/SQL Loader).
How to achive this?
I tried writing code like this ...
l_vc_command := 'sqlldr73'
||' USERID='||l_vc_username||'/'||l_vc_password||'@'||l_vc_connect_string
||' CONTROL='||l_vc_filepath||'Upload.ctl'
||' DATA='||LTRIM(RTRIM(l_vc_fileloc))
||' LOG='||l_vc_filepath|| l_vc_log_file || '_' || l_dt_sysdate_str ||'.log'
||' BAD='||l_vc_filepath|| l_vc_bad_file || '_' || l_dt_sysdate_str ||'.bad'
||' DISCARD='||l_vc_filepath|| l_vc_discard_file || '_' || l_dt_sysdate_str ||'.dsc';
HOST(l_vc_command,NO_PROMPT);
After this command i want to do some other code execution. so even if it fails or success, next code is executed. How to control this?
Please help..
Regards,
MilindForms6i running on W2000, Rdbms 8.1.7
in Forms I added a button TEST,
Trigger when-button-pressed : host('test.bat') ;
in directory .......\frm I added file test.bat :
REM ===============
cd /d C:\........\ldr
pause
sqlldr parfile=test.par
pause
type test.log
pause
exit
REM ================
now, pressing TEST button opens DOS window, telling me what's going on, running sqlldr, finally going back to forms
Are you using NO_PROMPT or NO_SCREEN option of HOST command ?
Had a look at Forms 4.5 manuals, there is no mentioning of (a)synchronously operation in connection with HOST command. -
SQL*PLUS using START command - please help me to understand
Hello dear friends,
I met one issue that i can't understand. Could you please explain me what is wrong in my logic.
I have created sql file called DUMMY.sql
the file context is:
SELECT dummy
FROM dummy_tbl
WHERE dummy_col=&dummy_var;
I go to SQL*Plus DB version (10.2.0.4.0).
I promt command: START DUMMY 1
and expecting *&dummy_var* to be replaced with *1* and query be executed as it is described in Oracle SQL*PLUS reference ([http://download-west.oracle.com/docs/cd/B12037_01/server.101/b12170/ch6.htm#sthref1058|http://download-west.oracle.com/docs/cd/B12037_01/server.101/b12170/ch6.htm#sthref1058] ).
But instead i'm getting Enter value for dummy_var:
please help me to understand
thanks in advance.You need to use &1 instead of &dummy_var.
The number references the position of the parameter to use;&1 is the first parameter, &2 would be a second parameter and so on.
SELECT dummy
FROM dummy_tbl
WHERE dummy_col=&1; -
Having problems trying to run a sql script using the command prompt.
I place my script at the root c:
open run SQL Command Line.
I connected to the database using connet userid/password
Then I tried to execute the script by doing
@test_add_comments
I am getting the error message.
SQL> @test_add_comments
SP2-0310: unable to open file "test_add_comments.sql"
Am I suppose to place this sql somewhere else?
test_add_comments.sql is
COMMENT ON COLUMN myTable.ID IS 'Primary Key' ;
COMMENT ON COLUMN myTable.REVIEWLOG_ID IS 'REFERENCE TO SAFE REVIEW LOG TABLE' ;
COMMENT ON COLUMN myTable.FAC_ID IS 'REFERENCE TO ALL FACILITIES' ;
COMMENT ON COLUMN myTable.HALLBUILD_ID IS 'REFERENCE TO HALL BUILDING' ;I figure it out.
open a sql worksheet and enter the falling commands in the run script.
@c:\your_script.sql
Execute it by clicking run script. -
Using UNIX command to copy desktop files/folders
Hello All. I need help using UNIX command(s) to copy text documents and or folders from my lab computers to my desktop at home. Since I have such a slow connection, I think this will work best. I need help with the cp command and the path mostly. Since all files would be in folders on the desktop (including documents (that "missed" the folders), I believe I could simply copy desktop contents? Thanks, J Langlois
What you want to do is SCP (secure copy) your documents to your remote host.
send this command to the computer with the documents
scp ~/Desktop/FILEOR_FOLDERNAME USERNAME@REMOTE_COMPUTER:~/Desktop/
Replace all the stuff in UPPERCASE with the correct vales for your situation.
Mini (Intel Core Duo) Mac OS X (10.4.8) -
Error in using the command "loadjava"(help me !)
When I use "loadjava" command to load the sample source code of
XML SQL Utility for Java,the errors as below:
C:>loadjava -u system/manager -v -r -t samp1.java
internal error:unanticipated
exeption:java.lang.NoClassDefFoundError:
oracle/aurora/sqljdecl/SqljDecl
java.lang.NoClassDefFoundError:
oracle/aurora/sqljdecl/SqljDecl
at oracle.aurora.server.tools.SourceFileReader.getScanner
(SourceFileReader.java:52)
at oracle.aurora.server.tools.SourceFileReader.getFirstName
(SourceFileReader.java:61)
at oracle.aurora.server.tools.LoadJava.processLoadAndCreate
(LoadJava.java:1094)
at oracle.aurora.server.tools.LoadJava.process
(LoadJava.java:1021)
at oracle.aurora.server.tools.LoadJavaMain.run
(LoadJavaMain.java:193)
at oracle.aurora.server.tools.LoadJavaMain.main
(LoadJavaMain.java:49)resolvers:
loadjava :1 errors
C:>
I looked for the class "oracle/aurora/sqljdecl/SqljDecl"
by executing the SQL query as below:
"select object_name from user_objects
where object_name like oracle%"
But I found only "oracle/aurora/sqljdecl/Token".
Maybe my envirenment have some errors(I get Oracle8i from
oracle's home by downloading)
I can't find out the reason.This matter have troubled me for a
long time.
Does anyone know the reason?please tell me.thanks a lot.
nullplz help me !!!!!
-
HELP!!! I deleted a .dbf file using OS command
Hi Experts,
I have accidently deleted a datafile, that is my index tablespace(.dbf) using OS command(AIX).
After that I was not able to open my database since the datafile is missing and I was not able to drop the datafile when the database in not open.
I dont any have recover option in my database to rrecover the datafile.
Can anyone pls tel me how can I delete the datafile when my database is not open.
Thanks in advance.
nonuday
Edited by: Nonuday on Apr 29, 2012 10:51 PMHi,
>
Its in not recovery mode, or you do not have any backup?
Then you have to drop that file from SQL as
SQL> alter database datafile 'Location' offline drop;
I tried what you have mentioned..
SQL> alter database datafile '/oracle/oradata11g/cboedbCBOEDEV_T24DISTINDEX1.dbf' offline drop;*
Database altered.*
SQL> alter database open;*
alter database open*
+*
ERROR at line 1:*
ORA-01589: must use RESETLOGS or NORESETLOGS option for database open*
SQL> alter database open NORESETLOGS;*
alter database open NORESETLOGS*
+*
ERROR at line 1:*
ORA-01610: recovery using the BACKUP CONTROLFILE option must be done*
SQL> recover using backup controlfile;*
ORA-00279: change 362471193 generated at 02/01/2012 15:59:03 needed for thread*
+1+
ORA-00289: suggestion :*
+/glosoft/oracle/oracle11g/app/oracle/product/11.1.0/db_1/dbs/arch1_24555_7443323+
+42.dbf+
ORA-00280: change 362471193 for thread 1 is in sequence #24555*
Specify log: {<RET>=suggested | filename | AUTO | CANCEL}*
ORA-00308: cannot open archived log*
+'/glosoft/oracle/oracle11g/app/oracle/product/11.1.0/db_1/dbs/arch1_24555_744332+
+342.dbf'+
ORA-27037: unable to obtain file status*
IBM AIX RISC System/6000 Error: 2: No such file or directory*
Additional information: 3*
What to do now??
pls help...
Edited by: 897910 on Feb 3, 2012 3:46 AM -
Installing SQL Server 2012 remotely via Powershell using Invoke-Command
I am trying to perform a SQL Server 2012 command line installation using Powershell Invoke-Command on Windows 2012 Datacenter.
The code I am using is as follows:
$ret = Invoke-Command -ComputerName $COMPUTER -ArgumentList $MEDIA,$ACTION,$FEATURES,$INSTALLDIR,$INSTANCEID,$INSTANCENAME,$SQLDATADRIVE,$SQLLOGDRIVE,$DOMAIN,$SQLSERVERSERVICEUSER,$SQLSERVICEPASSWORD,$PRODUCTKEY,$SQLSERVERSA,$username,$ADMINPASSWD
-Credential $cred -ScriptBlock {
param($MEDIA,
$ACTION,
$FEATURES,
$INSTALLDIR,
$INSTANCEID,
$INSTANCENAME,
$SQLDATADRIVE,
$SQLLOGDRIVE,
$DOMAIN,
$SQLSERVERSERVICEUSER,
$SQLSERVICEPASSWORD,
$PRODUCTKEY,
$SQLSERVERSA,
$USERNAME,
$PASSWD)
Set-Location $MEDIA
Import-Module ServerManager
if (-not [IO.Directory]::Exists($MEDIA)){
$hn = hostname
return 0,"Failed to find SQL Server Installer at $MEDIA on $hn"
$tran = ""
Try{
& $MEDIA\setup.exe /ACTION=$ACTION /Q /FEATURES=$FEATURES /IACCEPTSQLSERVERLICENSETERMS /UPDATEENABLED=False /INSTALLSHAREDDIR="$INSTALLDIR\Program Files\Microsoft SQL Server" /INSTALLSHAREDWOWDIR="$INSTALLDIR\Program Files
(x86)\Microsoft SQL Server" /RSINSTALLMODE="FilesOnlyMode" /INSTANCEID="$INSTANCEID" /INSTANCENAME="$INSTANCENAME" /INSTANCEDIR="$INSTALLDIR\Program Files\Microsoft SQL Server" /ENU="True" /AGTSVCSTARTUPTYPE="Automatic"
/SQLSVCSTARTUPTYPE="Automatic" /NPENABLED=1 /TCPENABLED=1 /RSSVCStartupType="Automatic" /ERRORREPORTING=0 /SQMREPORTING=0 /INDICATEPROGRESS /INSTALLSQLDATADIR="$SQLDATADRIVE\DATA" /SQLUSERDBDIR="$SQLDATADRIVE\DATA" /SQLUSERDBLOGDIR="$SQLLOGDRIVE\LOG"
/ASDATADIR="$SQLDATADRIVE\OLAP\DATA" /ASLOGDIR="$SQLLOGDRIVE\OLAP\Log" \ASBACKUPDIR="$SQLDATADRIVE\OLAP\Backup" \ASTEMPDIR="$SQLDATADRIVE\OLAP\Temp" /ASCONFIGDIR="$SQLDATADRIVE\OLAP\Config" /ASCOLLATION="Latin1_General_CI_AS"
/SQLCOLLATION="SQL_Latin1_General_CP1_CS_AS" /SQLSVCACCOUNT="$DOMAIN\$SQLSERVERSERVICEUSER" /SQLSVCPASSWORD="$SQLSERVICEPASSWORD" /AGTSVCACCOUNT="$DOMAIN\$SQLSERVERSERVICEUSER" /AGTSVCPASSWORD="$SQLSERVICEPASSWORD"
/ASSVCACCOUNT="$DOMAIN\$SQLSERVERSERVICEUSER" /ASSVCPASSWORD="$SQLSERVICEPASSWORD" /RSSVCACCOUNT="$DOMAIN\$SQLSERVERSERVICEUSER" /RSSVCPASSWORD="$SQLSERVICEPASSWORD" /FTSVCACCOUNT="NT AUTHORITY\LOCAL SERVICE"
/INDICATEPROGRESS > $out
} Catch [System.Exception] {
return 0,$_.Exception.ToString()
if ($tran -ne ""){
$out += $tran
return 1,$out
The media resides on the server that I am remoting to in powershell and the server is on the same domain. The credentials I pass are for a Domain Admin, but SQL Server fails to validate the credentials for the passed parameter for the sql service user with
a Access Denied.
If I run the same command with the same user directly on the server it works fine.
My guess is that the elavated privs for Administrator are not being set when using Invoke-Command? Is there a way to utilize powershell to install SQL Server 2012 with command line option using the invoke-command and passing credentials? Or is this a limitation
to the SQL Server installer. If there is can a example be provided?Ok, so with the help of some friends, we found a fix that works!
Prior to running the Invoke-Command I now run:
# enable CredSSP on a client computer; this command allows the client credentials to be delegated to the server01 computer.:
Enable-WsManCredSSP -Role Client -DelefateComputer server.some.domain.com
Then I add the -Authentication option to my Invoke-Command with option Credssp.
The install the works fine. Hope this helpes all. -
Help: use command "run" and "exec", no output
I create a script file Test.sql, and type "run d:\test.sql" in ttisql's command prompt, but there is no output, not even any error messages.
Command> run d:\test.sql;
Command>
I try to use "Prepare" and "Exec", still no output
Command> prepare 1 select * from employee;
Command> exec 1;
Command>
ttisql looks recognize these commands, but it doesn't execute them. Who knows the reason? thanks.Hi,
I create a script file Test.sql, and type "run d:\test.sql" in ttisql's command prompt, but there is no output, not even any error messages.What SQL statements are in Test.sql? To see more verbose output from ttIsql, try increasing verbosity. The default is 2. The highest (most verbose) is 4.
Command>verbosity;
verbosity = 2
Command> verbosity 4;
The command succeeded.
try to use "Prepare" and "Exec", still no outputTry adding a fetchone or fetchall command to retreive the result. e.g.
Command> prepare 1 select * from emp;
Command> exec 1;
Command> fetchone;
< 7369, SMITH, CLERK, 7902, 1980-12-17 00:00:00.000000, 800.0000, <NULL>, 20 >
1 row found.
Command> fetchone;
< 7499, ALLEN, SALESMAN, 7698, 1981-02-20 00:00:00.000000, 1600.000, 300.0000, 3
0 >
1 row found.
Command> fetchall;
< 7521, WARD, SALESMAN, 7698, 1981-02-22 00:00:00.000000, 1250.000, 500.0000, 30
>
< 7566, JONES, MANAGER, 7839, 1981-04-02 00:00:00.000000, 2975.000, <NULL>, 20 >
< 7654, MARTIN, SALESMAN, 7698, 1981-09-28 00:00:00.000000, 1250.000, 1400.000,
30 >
< 7698, BLAKE, MANAGER, 7839, 1981-05-01 00:00:00.000000, 2850.000, <NULL>, 30 >
< 7782, CLARK, MANAGER, 7839, 1981-06-09 00:00:00.000000, 2450.000, <NULL>, 10 >
< 7788, SCOTT, ANALYST, 7566, 1987-04-19 00:00:00.000000, 3000.000, <NULL>, 20 >
< 7839, KING, PRESIDENT, <NULL>, 1981-11-17 00:00:00.000000, 5000.000, <NULL>, 1
0 >
< 7844, TURNER, SALESMAN, 7698, 1981-09-08 00:00:00.000000, 1500.000, 0.000000e+
00, 30 >
< 7876, ADAMS, CLERK, 7788, 1987-05-23 00:00:00.000000, 1100.000, <NULL>, 20 >
< 7900, JAMES, CLERK, 7698, 1981-12-03 00:00:00.000000, 950.0000, <NULL>, 30 >
< 7902, FORD, ANALYST, 7566, 1981-12-03 00:00:00.000000, 3000.000, <NULL>, 20 >
< 7934, MILLER, CLERK, 7782, 1982-01-23 00:00:00.000000, 1300.000, <NULL>, 10 >
12 rows found.
Command>
Good luck.
Simon -
Calling SQL Loader from Forms 4.5 using HOST command in Win2000
One of my forms calls SQL Loader 7.3 using HOST command to load a csv file onto the database(Oracle 7.3) under Windows 2000 platform.
Only after sql loader finishes its operation the control should come to my form i.e. synchronous execution.
As of now its running asynchronously.
Is there any way to make it synchronous. If Not any other work arounds?
Environment Details
Forms [32 Bit] Version 4.5.10.6.0 (Production)
Windows 2000 Operating System
Oracle7 Release 7.3.2.3.2Forms6i running on W2000, Rdbms 8.1.7
in Forms I added a button TEST,
Trigger when-button-pressed : host('test.bat') ;
in directory .......\frm I added file test.bat :
REM ===============
cd /d C:\........\ldr
pause
sqlldr parfile=test.par
pause
type test.log
pause
exit
REM ================
now, pressing TEST button opens DOS window, telling me what's going on, running sqlldr, finally going back to forms
Are you using NO_PROMPT or NO_SCREEN option of HOST command ?
Had a look at Forms 4.5 manuals, there is no mentioning of (a)synchronously operation in connection with HOST command. -
hey,i forgot my login password,so i changed the password by using terminal command(reset password).now i have new user name with new password,
but i can't find my data which i have saved on mac.the storage is showing data used and free space on the disk
please help me out in this matter.How did you change your user name?
resetpassword wouldn't have done it. If you managed to create a new user, then your data is still in the old account. -
I keep getting the start menu and various programmes opening when I use a series of keys when working in my accounting programme, I am not using the command key and is very frustrating, can anyone help me? I am working on a Mac OS X Version 10.6.8, just need to know if I can reprogram the keys to stop this happening?
Safari browser and menu shortcuts:
http://docs.info.apple.com/article.html?artnum=42951
Mac OS X keyboard shortcuts:
http://support.apple.com/kb/HT1343
http://docs.info.apple.com/article.html?artnum=75459
Changing behavious of Function Keys:
http://support.apple.com/kb/HT3399?viewlocale=en_US
and more useful information on keyboard shortcuts here:
http://www.myfirstmac.com/index.php/mac/articles/mastering-keyboard-shortcuts
How to re-map individual keys:
http://scripts.sil.org/cms/scripts/page.php?site_id=nrsi&item_id=ukelele -
Help needed in SQL performance - Using CASE in SQL statement versus 2 query
Hi,
I have a requirement to find count from a bunch of tables.
The SQL I have gives the count of all members.
I have created 2 queries to find count of active and inactive members.
The key difference is only the active dates.
Each query takes 20 seconds to execute.
I modified the SQL to use CASE statement in the SELECT.
So after the data is fetched the CASE statement will evaluate the active date and gives 2 counts (active and inactive)
Is it advisable to use this approach. Will CASE improve SQL performance ? I have to justify this.
Please let me know your thoughts.
Thanks,
JHi,
If it can be done in single SQL do it in single SQL.
You said:
Will CASE improve SQL performance There can be both cases to prove if the performance is better or worse.
In your case you should tell us how it is.
Regards,
Bhushan -
Please tell how to store jpeg images in SQL Server using NI Database Connectivity Toolset.
http://www.w3schools.com/sql/sql_datatypes.asp
You setup a field as BLOB and store the binary of the picture there. Depending on the database it can be called differently as you can see in the link, in SQL server there's even a Image datatype.
/Y
LabVIEW 8.2 - 2014
"Only dead fish swim downstream" - "My life for Kudos!" - "Dumb people repeat old mistakes - smart ones create new ones."
G# - Free award winning reference based OOP for LV -
Need Help Can i use Merge command along with exist function in oracle?
I am using Merge command to update the destination table and updating the rows which are already in the destination table.
But what i want is to delete the existing rows from the destination table and insert fresh rows instead of updating the existing rows in the destination table.
So can we use exist function to check the existing rows and delete them and use merge command to insert the rows in the table.You definitely need to do a DELETE then INSERT since MERGE will not delete rows, although I'm not really sure what that gets you since the net effect would be the same as a MERGE over the same pair of tables.
If you really want to do it this way, then I would likely do something like:
DELETE FROM target_table
WHERE (columns_you_would_match_on) IN (SELECT columns_you_would_match_on
FROM source_table
WHERE predicate_you_would_use_in_using);
INSERT INTO target_table (column_list)
SELECT column_list
FROM source_table
WHERE predicate_you_would_use_in_using;John
Maybe you are looking for
-
I need some help! I just upgraded from PS CS2 to CC photoshop, bridge and lightroom CS6 CC. It is very different. I have 2 initial problems. 1) I do not have an option for mini bridge. It isn't in my PS dropdown menu nor an icon at the botto
-
i have timesten in windows xp. my timesten connect with my oracle database. i have more 100 data in my database. if i open with timesten there are 1 or more data miss. example i open employees table from user HR. there are 1 missoing data. or i open
-
Best way to play sound in a movie
I have a 40 second sound byte that I'd like to play in a movie. There are images that are tweened within the movie that I'd like to keep somewhat synchronized but only to the point that the sound byte doesn't end until the images have tweened (using
-
What type of memory cards can be used on hp6510
what memory cards are used in hp 6510
-
Reader 11.0.04 on Win 7 screen resolution issue
Hello, There are two Windows accounts on my machine (Windows 7, home). When I log into one account, Adobe Reader (11.0.04) works fine. When I log into the other account, and open Reader, the screen resolution changes, and the Reader screen looks hu