How can I write a sql with a Union.

How can I write a sql with a Union.


Select emp_name, emp_no, emp_sal of the emp


If show_Less_100000 = "Yes" then emp_sal < 100000 (all values less than 100000)

otherwise the full list.



Thank you
Harsha

Published by: taty on July 31, 2012 11:28
SQL> variable show_Less_100000 varchar2(3)
SQL> exec :show_Less_100000 := 'Yes';

PL/SQL procedure successfully completed.

SQL> select  ename,
  2          empno,
  3          sal
  4    from  emp
  5    where (
  6               :show_Less_100000 = 'Yes'
  7           and
  8               sal < 2000
  9          )
 10       or nvl(:show_Less_100000,'No') != 'Yes'
 11  /

ENAME           EMPNO        SAL
---------- ---------- ----------
SMITH            7369        800
ALLEN            7499       1600
WARD             7521       1250
MARTIN           7654       1250
TURNER           7844       1500
ADAMS            7876       1100
JAMES            7900        950
MILLER           7934       1300

8 rows selected.

SQL> exec :show_Less_100000 := 'All';

PL/SQL procedure successfully completed.

SQL> select  ename,
  2          empno,
  3          sal
  4    from  emp
  5    where (
  6               :show_Less_100000 = 'Yes'
  7           and
  8               sal < 3000
  9          )
 10       or nvl(:show_Less_100000,'No') != 'Yes'
 11  /

ENAME           EMPNO        SAL
---------- ---------- ----------
SMITH            7369        800
ALLEN            7499       1600
WARD             7521       1250
JONES            7566       2975
MARTIN           7654       1250
BLAKE            7698       2850
CLARK            7782       2450
SCOTT            7788       3000
KING             7839       5000
TURNER           7844       1500
ADAMS            7876       1100

ENAME           EMPNO        SAL
---------- ---------- ----------
JAMES            7900        950
FORD             7902       3000
MILLER           7934       1300

14 rows selected.

SQL> 

SY.

Tags: Database

Similar Questions

  • How can I write the SQL query for this requirement?

    Hello

    I have a table that looks like this:

    NAME | ANNUAL |     VALUE
    ==== | ====== | =====
    execno |     480.     000004
    step |      480.     0400
    SCNA |     480. cd_demo
    System |     480.     D47-010
    type |     480.     step
    free_text |     480.     stage 400
    rbare |     480.     RBA-1
    execno |     482. 000004
    SCNA |     482. cd_demo
    System |     482.     D47-010
    free_text |     482.     step 300
    step |          482.          0300
    type |      482.     step
    rbare |     482.     RBA-1
    execno |     483.     000001
    type |     483.     step
    rbare |     483.     rke1
    SCNA |     483.     rke10
    step |     483.     0240

    Now, say that I want to fetch ONLY annual with execno = '000004' and '400' = step and scna = "cd_demo" and system = "d47-010' and type = 'step', how to write SQL code?
    At first, it seemed like a simple writing query but I've been struggling with it for hours without success. I must admit though that I'm not strong in SQL :-)
    There, can anyone help? Please...

    Thanks in advance.

    Emmanuel

    Published by: user12138559 on October 30, 2009 03:05

    Hi, Emmanuel.

    Welcome to the forum!

    Here's a way to do what you asked:

    SELECT       doc_id
    FROM       table_x
    GROUP BY  doc_id
    HAVING       SUM (CASE WHEN name = 'execno' AND value = '000004'  THEN 1 END) > 0
    AND       SUM (CASE WHEN name = 'step'   AND value = '400'     THEN 1 END) > 0
    AND       SUM (CASE WHEN name = 'scna'   AND value = 'cd_demo' THEN 1 END) > 0
    AND       SUM (CASE WHEN name = 'system' AND value = 'd47-010' THEN 1 END) > 0
    AND       SUM (CASE WHEN name = 'type'   AND value = 'step'    THEN 1 END) > 0
    ;
    

    If you think that a WHERE clause would be used, but WHERE does apply to a single line. You need a condition that checks several rows in the same group.
    WHEN has an effect something like WHERE.

    Published by: Frank Kulash, October 30, 2009 06:26

    This solution assumes that (name, annual) is unique.

  • How can I write the SQL for this result?

    Hello my dear,
    Here first of all the script.
    CREATE TABLE ACC_TEST(
    AD_ID NUMBER,
    AD_NAME VARCHAR2(50),
    AD_SPM_ID NUMBER);
    /
    the data are
    Insert into ACC_TEST (AD_ID,AD_NAME,AD_SPM_ID) values (136,'Saleh Ahmed',129);
    Insert into ACC_TEST (AD_ID,AD_NAME,AD_SPM_ID) values (142,'Hamidur Rahman',136);
    Insert into ACC_TEST (AD_ID,AD_NAME,AD_SPM_ID) values (124,'Jasim Uddin',null);
    INSERT INTO ACC_TEST (AD_ID,AD_NAME,AD_SPM_ID) VALUES (129,'Sazib',124);
    I need the following result, when passing a value of Ad_Id. For example I go to 142 then result must be
    Select Ad_Id,Ad_Name
    From..
    ...
    where ad_id=142
    
    Ad_Id   Ad_Name
    136     Saleh Ahmed
    129     Sazib
    124     Jasim Uddin
    
    If I Pass Ad_Id=136 Then Result Should Be
    Ad_Id   Ad_Name
    129     Sazib
    124     Jasim Uddin
    
    
    If I Pass Ad_Id=129 Then Result Should Be
    Ad_Id   Ad_Name
    124     Jasim Uddin 
    Database 10 G XE

    Any help will be useful

    Hello

    HamidHelal wrote:
    WoW! You are totally my point. How do you understand that? l

    Guess luck. Guessing is generally not the best way to solve problems. It is generally faster and more reliable to say exactly what you want, as well as give an example.

    fallen little more that I want to know, if I want to restrict the output not more then 2, which would be sql?

    Now, you're not even giving for example!
    Maybe you want something like this:

    SELECT     ad_id
    ,     ad_name
    FROM     acc_test
    WHERE     LEVEL     BETWEEN 2 AND 3          -- Changed
    START WITH     ad_id     = :target_ad_id
    CONNECT BY     ad_id     = PRIOR ad_spm_id
    ;
    

    which will show just the mother and grandmother of the given line.

    I work with the developer of forms a lot. Knowledge of SQL is like sql oracle (9i cerfitication) book. But this type of sql is not available here.
    where can I learn this type of sql? SQL different then regular?

    Certification is another matter entirely.
    There are books and web sites dealing with more advanced techniques. Sorry, I don't know any good enough to recommend. Some authors (such as Tom Kyte) are always good.

    Here are a few sites that explain CONNECT BY queries:
    http://www.adp-GmbH.ch/ora/SQL/connect_by.html
    http://www.oradev.com/connect_by.jsp

  • How can I write double DVD with my DVD UJ 820 burner?

    Hello, I own a laptop satellite, and my problem is that she cannot write to double DVD, I think I should update the firmware but I can't find anything, recently I had the same problem with my desktop pc and to solve when I update the firmware of its own nec dvd burner Anyone know where I can find an update of the firmware or something to solve my problem?

    Hi Chris

    CD and DVD burning and playback with different readers are a never-ending story.
    I use an external burner and believe me; I tested more than 10 different media from different manufacturers.
    I could burn some media but not read and read but not burn :(
    I think you should also test different DVD.

    In my manual, I found a list with the CD and DVD compatible. Eventually, you will also find the same list of supported media in the pre-installed user manual you.

  • How can you write "A SEQUENCE OF characters" in sql... ?

    Gurus of the afternoon,

    A fast if all goes well. I am eager to return all records where a family of field name! = A SEQUENCE OF characters IN THE fnd.description field.

    How do I do this in SQL?
    SELECT DISTINCT fnd.CREATION_DATE, fnd.user_name, fnd.start_date,  per2.last_updated_by,
    per2.last_update_date,per2.employee_number, per2.EMAIL_ADDRESS, 
    per2.full_name, fnd.LAST_LOGON_DATE 
    
    FROM fnd_user fnd, per_people_f per2
    
    WHERE  fnd.employee_id  = per2.person_id(+) 
    
    AND fnd.end_date IS NULL
    
    how do I rewrite this..? ** AND SUBSTR(per2.LAST_NAME, 2, 6) !=  SOME SEQUENCE OF characters IN per2.EMAIL_ADDRESS **
    
    aND per2.EMAIL_ADDRESS LIKE '%priddle%' 
    ORDER BY 2 ASC;
    How can I write in SQL ' a SEQUENCE OF characters IN per2. As of email_address one ' % the same characters as its in SUBSTR (per2. LAST_NAME, 2, 6) %'...?

    I hope it's unclear! Please ask any questions.

    Thanks for the research.

    S

    Two ways:

    AND per2.EMAIL_ADDRESS NOT LIKE '%'||SUBSTR(per2.LAST_NAME, 2, 6)||'%'
    

    or

    INSTR(per2.EMAIL_ADDRESS,SUBSTR(per2.LAST_NAME, 2, 6),1) = 0
    

    Published by: AP on July 30, 2010 08:30

  • How can I write a letter in french with Pages

    I use my computer in English, and I have to write an essay in french

    So, how can I write a letter in french with Pages

    Hi Luke,.

    If you are familiar with the French keyboard layout, you can move from the keyboard to this provision.

    If not, you can acess of the accents you will need the English KB layouts using (for example) option-~, then press e to e, or -e option, then press e to e. see the viewer keyboard for other options. Open the keyboard Viewer, and then press option key to display the keys to use for each accent.

    If all the accents you need are not available from an English keyboard, you can still list a French KB language as a 'second choice' and switch to it when you need an accented letter.

    Choice of the keyboard are defined in system preferences > language and text > input sources. If you choose more KB a page layout, the entry menu (a flag) will appear in your menu bar. The indicator shows the currently active KB.

    Kind regards

    Barry

  • How can I write the value of floats Unitronics vision230 PLC with modbus Ethernet

    How can I write the value of type Float in unitronics PLC Vision230 modbus ethernet (Ethernet Master Query.vi MB) usinsg I read and write register 32 bits, for example, I want to write the value 23.45 2nd Add. MF. And registry MF is the 32-bit registry. I read and write register 32-bit.

    Narendra.

    Narendra,

    Two characters can type cast into a uint16 you VI supports.

    To summarize. Take one (4 bytes). Flatten it to a string (4-byte) divided this string into two parts of 2 bytes each. Cast in u16 (16 x 2 = 32-bit).

    However, if you really want to follow the IEEE standards then you will need refer this KB. His is not that simple, but seems closer to what you are looking for.

    Amit

  • How can I write a DVD blu - ray on a mac?

    How can I write a DVD blu - ray on a mac? I tried a blu - ray burner and (if necessary) the software to use.

    I found the BE14NU40, BD playback/BD write LG, but I don't know if it's Mac compatible.

    Can anyone advice a good burner + software?

    I used one of them for several years and it works very well with Mac:

    ta-drive-solution-blu-ray-6x-dl-dvd-r-rw https://www.MacFixIt.com.au/OWC-mercury-Pro-super-multi-blue-Blu-ray-external-SA...

    Al

  • How can I write a digital waveform to the digital output (traditional DAQ)

    Hello

    I use a NI 6023e, PCI, with 8 digital outputs. I generated a digital waveform. How can I write for a specific digital production line now?

    I only have Labview 7, so I can't use DAQmx.

    Thank you very much


  • How can I protect a file with a password?

    Original title: password

    Please, tell me how can I protect a file with password, folder, a CD, or a DVD. Is there a suitable and reliable and verified software? Please, give me web comments on sites where to find necessary software. I need in order if my CD or DVD discs will be stolen by a stranger or to reach people I did not trust. I need only for private use. You see, I don't have an iron safely to the place I live. I hope that you will understand me. Thank you in advance. John

    Hello, Tommy Stanley. I realized from your questions that you can imagine that I will earn money selling the CD protected by word or DVD discs telling buyers the password. No, I'm not a sales man. Only for me on the extreme case, that my disks will be stolen or to reach people, I do not trust. I guess that to set a password that is easier then encrypt disks. But I wonder to know how to encrypt CD or DVD discs and that means encrypted drive. Through what she may be to read? Please, I explain my situation (I live in time with people that I don't have confidence). Please, give me some reliable advice concerning my question. Now, for me it very seriously. I hope you understood me. Thank you in advance, Shenan Stanley.

    I think you read things in my simple questions that weren't there.  I asked because if it is stored on a single computer/use on one computer by one person - the solutions are simpler and more readily available than if you plan to send this information to someone else so that they treat.

    I recommend you read this:
    http://www.computerhope.com/issues/ch000705.htm

    If this isn't a shared computer... (It is yours, you can use only.)

    I suggest that you see if you can lock the computer closed (with a physical cable/lock).  You add a password to your system SETUP or BIOS so that no one can change the settings of operating system and maybe even a STARTUP password so it can not even start without enter you a password.  Also change the BIOS settings so that it will only start from the hard drive installed in the machine.  With the Setup/BIOS password, you can change back to something later.

    AxCrypt and TrueCrypt are free and good encryption tools.

    Regarding the CD/DVD - you don't encrypt the media - you encrypt everything you would write for them and you will probably need to copy off the power and check that the files on them are not read-only before you can decrypt in most cases.

    By the way - physical security outweighs almost all other types of security.  Which means you need to physically secure the computer before you bothder same thing with another.  Locking the computer case closed and adding the password after changing startup opportunities, I would consider good physical security in your case.

  • How can I write in a table cell (row, column appear) in a databae?

    How can I write in a table cell (row, column appear) in a database using LabVIEW Database Toolkit? I use Ms Access. Suppose I have three columns in a table, I write 1 row of the 1st column, then 1st rank of the 3rd column. The problem I have is after writing the 1st column of 1st row, the reference goes to the second row, and if I write in the 3rd column, he goes to the 2nd row 3rd column. Any suggestion?

    When you perform a SQL INSERT command, you create a new line. If you want to change an existing line, you must use the UPDATE command (i.e. UPDATE tablename SET column = value WHERE some_column = some_value). The some_column could be the unique ID of each line, date and time, etc.

    I don't know what is the function to use in the Toolbox to execute a SQL command, since I do not use the Toolbox. Also, I don't understand why you don't do a single INSERT. It would be much faster.

  • How can I write a whole byte to a port of digital I/o on a NI7340

    I was able to find a Port.flx of e/s from reading that allows me to read all 8 bits at a time. I can't find a Port.flx VI e/s writing. How can I write all 8 bits at a time?

    Take a look at the value of MOMO.flx of I/o Port. Here is general information about DIO with Motion and here an explanation on the Protocol of MOMO (should we need to Off).

  • How can I sort a coloumn with names of months?

    Hi I m using oracle 11 g how can I adjust the coloumn with month names

    My requiremnt is to sort the coloumn from July to June

    means that the July should be the first and June shoud be the last month of the year

    need help thnx

    You can also...

    kendenny wrote:

    Or this

    SQL > WITH m AS
    2 (SELECT "January" mname FROM dual)
    3 UNION ALL
    4. SELECT "February" mname dual FROM
    5. ANY TRADE UNION
    6. SELECT 'Mars' double mname
    7 UNION ALL
    8. SELECT "in April" mname dual FROM
    9 UNION ALL
    10. SELECT mname "Peut" double
    11 UNION ALL
    SELECT 'June' 12 mname dual FROM
    13 UNION ALL
    14. SELECT "July" mname dual FROM
    15 UNION ALL
    16. SELECT mname "Augustus".
    17 DOUBLE
    18 UNION ALL
    19 SELECT "September" mname
    20 DOUBLE
    21. ANY TRADE UNION
    22. SELECT "October" mname
    23 DOUBLE
    24 UNION ALL
    25 'November' SELECT mname
    26 DOUBLE
    27 UNION ALL
    28 mname SELECT "December".
    29 DOUBLE)
    30 SELECT mname
    31 m FROM
    32 ORDER BY TO_CHAR (ADD_MONTHS (TO_DATE (m.mname, 'Month'),-6), 'MM');

    MNAME
    ---------
    July
    August
    September
    October
    November
    December
    January
    February
    March
    April
    May
    June
    12 selected lines

  • How can I configure the element with the script names?

    Could Hello someone give me a hand?

    I created symbols on the stage of this script below.

    ------------------------------------------------------

    for (k = 0; k < 5; k ++) {}

    sym.createChildSymbol ("mySymB", "Stage");

    }

    ------------------------------------------------------

    How can I configure the element with the script names?

    Because, when I try to control a symbol by using the getSymbol("---") command.

    I need to know the name of the item given to each symbol.

    Concerning

    Yes, you're right.

    Using 'Code-Example' If you write sym.getSymbol ("mySymB") that edge returns the undefined value.

    With "Drag-and-drop-Example", you can use sym.getChildSymbols ().

  • Two part question: 1 How can I write a script for long Division, 2. How can I make my form?

    1. I have a field where I need to write a formula for a division problem: (power/population) / 365.  When I use the simplified field notation I get an error: the entered value does not match the format field.  I want the answer as a number with no decimal point.  If I format the field to 'no format' I don't get an error message but the answer comes with up to 10 digits after the decimal point.  I'd rather have the answer in integer without figures after the decimal point.  How can I write this in the custom calculation script?

    2. on accessibility - I never checked on the display/a Mode and unlocked the Acrobat/PDF compatibility.  Some users do not have a problem by filling out the form, but others are not allowed to fill that PDF/A is enabled for their document.  Is this something on their end?  Or is it something on my end blocking them?

    If you multiply by 100, it appears correctly. But if you need to retain the value of the field, you need to use a script to Format custom instead. If you need help, post again.

Maybe you are looking for

  • Cancel the Apple music

    Please cancel my music from Apple.  I do not use it. Thank you.

  • Reentrant VIs - disappear?

    Debugging with Labview 8.6.1, sometimes, when you think that you have completely closed a VI, it continues to operate but It doesn´t appear in Labview so it is impossible to "close" it. The bad news is that you leave LabView being connected SubVIs Im

  • Lexmark x 2250 printer-scanner-copier

    My printer will not sync and work on my computer. How can I make it work?

  • Necessary Assistsance with Aspire E11 - E3-111-C5JR

    Hi team, Asking for your help. I have Aspire E11 - E3-111-C5JR and I just want to know if I can pass my RAM from 2 GB to 4 GB without any conflict in my Machine? Can I see the local computer shop and ask them to updrade my RAM or I need to visit Acer

  • LifeLog does not sleep

    The application does not sleep, because since I got on the phone, its been two days. How can I fix it?