Sql query-filter if 1 set of data exists and in the same time 2 set doesnt

Hi guys,
I need to write a query where I filter on certain data being present, but in the same time other data from the same table being not present.
For example:
ProceduresTable:
Type 1
Type 1
Type 2
Type 2
Type 1
MyTable:
Name
OtherFields
JoiningTable (many to many)
ProceduresTable_Key
MyTable_Key
I need to select all records from MyTable and Procedures for which there are procedures from Type 1 but there are no procedures from Type 2 in the same time.
So far I've been only able to do that by using subqueries and I think there should be an easier way to do that.
Here is what I have:
Select * From MyTable, Procedures, JoiningTable Where JOINING_CONDITIONS AND Type = 1 AND NAME_SOME_COLUMN NOT IN (SELECT NAME_SOME_COLUMN FROM ... WHERE Type = 2 and inner.Name = outer.Name)
Hope you understand my meta code. I have Oracle 9 db.
Thanks a lot!

Hi,
Welcome to the forum!
Whenever you have a question, it helps if you post a specific example. Include CREATE TABLE and INSERT statements for a little sample data, and also post the results you want from that data.
if you can use commonly available tables (like those in the scott or hr schemas) to illustrate your proble, then you don't have to post the sample data; just the results.
For example, I think you're asking something like this:
"How can I find information about people in the sciott.emp table who are in a department that has at least one CLERK ( that is, a row with job='CLERK') but no SALESMAN? That is, I want these results:
{code}
ENAME DEPTNO JOB
CLARK 10 MANAGER
KING 10 PRESIDENT
MILLER 10 CLERK
JONES 20 MANAGER
FORD 20 ANALYST
ADAMS 20 CLERK
SMITH 20 CLERK
SCOTT 20 ANALYST
{code}
One way is to use CASE expressions instead of WHERE clauses to test for the criteria, then using the reults of the CASE expressions in the WHERE clause.
For example:
WITH     got_cnts     AS
     SELECT     ename,     deptno,     job
     ,     COUNT ( CASE
                         WHEN  job = 'CLERK'
                   THEN  1
                     END
                ) OVER (PARTITION BY deptno)     AS clerk_cnt
     ,     COUNT ( CASE
                         WHEN  job = 'SALESMAN'
                   THEN  1
                     END
                )     OVER (PARTITION BY deptno)     AS salesman_cnt
     FROM     scott.emp
SELECT     ename,     deptno,     job
FROM     got_cnts
WHERE     clerk_cnt     > 0
AND     salesman_cnt     = 0
;The problem here is that you can't always tell, by looking at any one row, if it should be included or not; in this case, you need to know something about the department as a whole. Analytic functions can look at the department as a whole, but analytic functions are computed after the WHERE clause is applied, so to use the results of the analytic functions in a WHERE clause, we need to do the analytics first, in a sub-query, and the WHERE clause later.
Sometimes (as in the example above) analytic functions are useful; other times, aggregate functions are more appropriate, depending on the exact requirements.
Edited by: Frank Kulash on Apr 12, 2010 9:00 AM

Similar Messages

  • Can I import two sets of data to Essbase at the same time?

    For example, use two MaxL Scripts to import data to one Essbase Application Datatbase in the Same time, is there any impacted or will fail one of them or nothing will happen but just slower?

    Hi,
    It is possible you run 2 dataloads at the same time, there will be probably be an impact in performance than just loading one file at a time, not sure of the impact, you will have to test.
    If you are talking about a BSO cube you could also have a look at the essbase configuration setting DLTHREADSWRITE to see if you can improve the dataload time by increasing the threads.
    If it is an ASO cube then you should be able to do multiple dataloads into different buffers, though you have to commit them to the database at the sametime.
    Cheers
    John
    http://john-goodwin.blogspot.com/

  • Create SP that returns value and at the same time displays query result in output window

    I would like create an SP which will return the records from the table and also return value to my c# client application.
    For Example:
    Select * from employee returns all the query results in output window.
    Now I want to create an SP
    Create procedure Test
    As
    Declare @ret int,
    Select * from employee
    set @ret = Select count(*) from employee
    if @ret > 0
    return 1
    else
    return 0
    The above algo should return 1 0r 0 to c# client application and at the same time display all employees in sql query output window.
    Can u pls help in this regard.

    The above algo should return 1 0r 0 to c# client application and at the same time display all employees in sql query output window.
    Why?  and No!
    Why?  Your procedure generates a resultset of some number of rows.  You check the resultset for the presence of rows to determine if "anything is there".  You don't need a separate value to tell you this.  Note that it helps
    to post tsql that is syntactically correct.   While we're at it, if you just need to know that rows exist there is no need to count them since that does more work than required.  Simply test for existence using the appropriately-named function
    "exists".  E.g., if exists (select * from dbo.employee). 
    No!  A stored procedure does not display anything anywhere.  The application which executes the procedures is responsible for the consumption of the resultset; it chooses what to do and what to display. 
    Lastly, do not get into the lazy habit of using the asterisk in your tsql code.  That is not best practice.  Along with that, you should also get into the following best practice habits:
    schema-qualify your objects (i.e., dbo.employee)
    terminate every statement - it will eventually be required.

  • It is possible to charge an iPad3 over USB and transmit data over USB at the same time?

    Hello,
    it is possible to charge an iPad3 over USB and transmit data over USB at the same time?
    If yes, how?
    Thanks
    Best regards

    OK!?
    That is right that the USB data oins are not connected to +5V pin.
    But i found a description for a self built power supply for iPad.
    http://timothyb.net/DIY_iPad_2_USB_Charger.html
    and
    https://www.mikrocontroller.net/topic/262610?goto=2726627#2726627
    The description say: data pin D- need a voltage level of 2V and D+ 2,857V
    when the data pins have this special voltage levels and VCC has +5V only then the iPad is charging.
    The voltage "D+/D- coding" is the key for the iPad to charge.
    OK now back to my problem.
    The regular USB data pin voltage level is 0,3 - 3.,0 voltage. When the iPad is charging the data pins have this special voltage level. Now i try to transmit data over the usb data pins with the. Normaly the USB port transmit the data with a voltage level of max. 3V.
    And here my problem. The higher voltage level at the data pins cares therefor that the iPad stop the charging.
    Is that correct?

  • How do I link fields on two different sheets? What I am trying to do is enter data on one sheet and at the same time in is entered on a second and sometimes third sheet at the same time

    PLEASE FORGIVE ME THIS IS THE FIRST TIME I AM USING THIS
    1) How do I get data entered into 2 or 3 fields on different sheets all at the same time?

    Hi David,
    Welcome to Apple Support Communities!
    In Pages, you can have several sheets in a document, and several tables on a sheet. You can link cells between tables and sheets.
    You can not link from one document to another, but who needs to?
    To link cells from Table 1 on Sheet 1 to Table 1 on sheet 2,  click on destination cell, type =, then click on the source cell. Under the Insert menu, choose Fill if you wish to duplicate a range of cells.
    This is a bit different from Microsoft Windows Excel, but you will soon get the hang of it.
    You can download the Numbers User Guide from the Help menu.
    Happy Macintoshing!
    Ian.

  • How do I get music and games which I purchased for my daughter through my iTunes account onto her iPad mini  but at the same time set up a separate iTunes account for her iPad?

    My daughter  used to use my old iPod and all the music and games that she wanted went through my e-mail/iTunes account.  She has moved onto an iPad mini but this is still in my account.  I want to set up an e-mail and iTunes account for her so that my iPhone doesnt get jammed up with all her stuff.  If I do this I think that all the stuff which I've bought will be lost to her.  How can I get round this?

    Apple devices can hold protected content from up to five different accounts, however updating apps purchased over more than one account (as far as I'm aware) requires signing in and out of each account. You may be better off continuing to use one account for your family, as I do, but disabling the options on each device for the automatic download of purchases made on the account, and in iTunes, the automatic inclusion of new apps when syncing from the library to the device.
    tt2

  • Use 2 Data Acquisiton Cards at the same time

    We are using PXI chasis for developing a test system. We want to use one card (PCI 6713) for analog output to the unit under test (UUT)and want to use the Dig I/O card to capture the response of the Device under test. currently i have two separate VIs for outputting data to UUT and for capturing response.
    can someone suggest a method to integrate this function in one VI. This way we could capture the real time response while the test stimulus is being sent to the UUT.
    Thanks

    Hello Shabu,
    Thank you for contacting National Instruments.
    To obtain real-time response while the test stimulus is being sent to the unit under test (UUT), you should place a single point Analog Output (AO) and Digital Input (DI) in the same while loop. In this configuration, you will be sending an AO to the UUT and reading the resulting DI for each iteration.
    If this doesn�t solve your problem, please respond with more information. I would also be happy to take a look at your existing code and offer further ideas.
    Have a great day.
    Sean C.
    Applications Engineer
    National Instruments

  • Defining Date range and using the same range to search the documents.

    Hi Sap Gurus,
    in our business there are some documents which do have Validity period, like say Inspection certificates and valid for say 10 months, ex..  JAN 25th 2009 to Oct 24th 2009
    we store this certificate in DMS and link to some SAP object say an Asset,
    we have a requirement to list all the documents based on the expiry date range. say to get a list of documents which are about to expire in 15 days, or the list of documents which have already expired
    I tried to define a characteristic in date format, but it is a single value field, and search is only supported on that specific value only.
    like we cannot serch the DIR falling in between this Date Ranges.
    also report of Documents which are to expire in 15 days could not be got.
    is there a way to meet this requirement , if it is through a development also please tell me how the logic could be built
    Thanks and regards
    Priya S

    Hi SAP Gurus,
    Thanks much Thomas for your Promt reply.
    The solution provided by Thomas really works but the same thing is not possible in EDMS,
    in Easy DMS we cannot manually give any value in the date characteristics field, the system will ask to fill from the date window format.
    so we cannot enter < or > <> value in characteristics, hope there is any note or other procedure to get the same funtionality.
    please if any one worked on the same with EDMS  let me know
    Thanks and kind regards
    Priya S

  • Can I get 2 sets of headphones to work at the same time on my powerbook?

    For example, one USB set and one regular mini jack? I have played around in audio settings but don't see a way to do it. thanks

    You might try a simple headphone splitter like this:
    http://www.amazon.com/Belkin-F8V234-WHT-APL-Headphone-Splitter/dp/B0000UV2AW

  • Find a way to set Accordion open multi panel at the same time!

    Now, I can set all the panel close by default !
    But my client want when some panel has open , then he click
    on the other panel, it doesn't make the pervious open panel closed,
    until you click on it !
    Does someone can help me?

    Hi,
    you can use Collapsible Panel Group widget to achieve this
    behavior.
    Please take a look over this
    sample
    page.
    Diana

  • Condition records- setting printer for multiple vendors at the same time

    Hi all,
    I have maintained condition record for POs for Key combination of Doc type,Purch Org and vendors.Now for a particular doc type and P.Org , I have around 50 vendors. I need to change the printer for all these 50 vendors to 'printerx'.Is it possible? I tried selecting multiple vendors at a time and changed the printer but its not working.

    Hi Saurav ,
    You can achieve this through SCAT transaction.
    For running SCAT take the help of ABAP team.
    I hope u might be having the list in the form of text file.
    If not , download the same from NACH table.
    Regards
    Ramesh Ch

  • I cannot use data and voice at the same time.

    I cannot use data and voice at the same time.
    I am on Wifi (connected) and at the same time I am on a voice call. when I switch to my RSS feed reader it does not sync it comes out with a message cannot connect to internet, I thought it is a problem with the feed reader application, IE 10 behaves the same I cannot browse when I am on a voice call.
    This is a very basic issue, am I missing something? Please help.
    My Model is lumia 820 with the latest portico update.
    TIA
    Sandeep

    I am aware that packet data via EDGE and voice cannot happen at the same time, surprisingly when I am on voice call I cannot connect to internet via Wifi too

  • I am unable to male myself heard on out going VOIP calls. My ISP suggests this is due to data uploading at the same time. How can I stop this happening?

    When I make phone calls using VOIP the person answering says they cannot hear me properly. My ISP suggests that this may be due to data up loading at the same time. The problem has been going on for at least two days. What can I do? The only thing I have changed recently is to go over to photo from iPhoto.

    In the Photos preferences Pause the Photos upload when you need to use the internet - basically I am only uploading at night and when we are both out of the house -
    For me the upload is a very slow process that kills everything else on my network
    LN

  • Multiple Users accessing the same core set of queried data

    Hi. We have a small call center and we want to build an app where the users can query the same core set of data and use it to initiate calls to study participants. The trick is that they will also need to update each record with information from the call. So we need to stop two call center agents from potentially calling the same participant at the same time.
    Is there a good method or best practice for creating a app to do this? The concern is that multiple call center agents would be querying the screen with the same core set of records (for example, querying by 'Ready for Call' status). When a call is placed the agent will have a conversation with the participant and ultimately end up updating the record after about 10 minutes. So my question is whether there is a good way to keep multiple agents from working with the same record (e.g. calling the same participant simultaneously)?
    Right now it seems that Oracle will lock a record for update, but only after an agent has initiated a change to the record. This still leaves a window of opportunity for two or more agents to be calling the same participant at the same time.
    Any thoughts or ideas on this would be greatly appreciated. Thanks so much.

    By 'standard record locking system' do you mean there is nothing I need to do programatically? No block level properties to change?
    So you are saying this is just the way it always works. So as soon as one of our call center agents opens a record all I have to do is create a pending update to any field?
    But won't another user be able to open the form and just query that record not knowing another user has it open?

  • SQL query: select billaddress if no delivery address exist.

    hi sql expert,
    The Query shall filter all invoices by date, articles and show the delivery address. Problem: Not every customer has deposited a delivery address. In this case the billing address is to be taken.
    How can this be done ?
    This query
    SELECT T0.[CardName], T3.[ZipCode],T3.[Street], T1.[ItemCode], T1.[Dscription], T1.[ShipDate], T1.[Price], (T1.[Price] * T1.[Quantity]) as "Gesamtpreis in €", T1.[FreeTxt],substring(T1.Freetxt,0,5) as "Grundpreis in €",substring(T1.Freetxt,9,6) as "TS-Wert in %", T1.[Quantity] FROM OINV T0  INNER JOIN INV1 T1 ON T0.DocEntry = T1.DocEntry INNER JOIN OCRD T2 ON T0.CardCode = T2.CardCode INNER JOIN CRD1 T3 ON T2.CardCode = T3.CardCode WHERE CONVERT(nvarchar(8), T1.ShipDate, 112) BETWEEN '[%FromDate]' AND '[%ToDate]'
    and T1.Itemcode = [%0] GROUP BY T0.[DocNum], T0.[CardName], T3.[ZipCode],T3.[Street], T1.[ItemCode], T1.[Dscription], T1.[ShipDate], T1.[Price], T1.[FreeTxt], T1.[Quantity]
    UNION ALL
    SELECT T0.[CardName], T3.[ZipCode],T3.[Street], T1.[ItemCode], T1.[Dscription], T1.[ShipDate], -T1.[Price], -(T1.[Price] * T1.[Quantity]) as "Gesamtpreis in €", T1.[FreeTxt], ('-' + substring(T1.Freetxt,0,5)) as "Grundpreis in €",substring(T1.Freetxt,9,6) as "TS-Wert in %", -T1.[Quantity] FROM ORIN T0  INNER JOIN RIN1 T1 ON T0.DocEntry = T1.DocEntry INNER JOIN OCRD T2 ON T0.CardCode = T2.CardCode INNER JOIN CRD1 T3 ON T2.CardCode = T3.CardCode WHERE CONVERT(nvarchar(8), T1.ShipDate, 112) BETWEEN '[%FromDate]' AND '[%ToDate]' and T1.Itemcode = [%0]
    GROUP BY  T0.[DocNum], T0.[CardName], T3.[ZipCode],T3.[Street], T1.[ItemCode], T1.[Dscription], T1.[ShipDate], T1.[Price], T1.[FreeTxt], T1.[Quantity]
    Thanks a lot!

    hi,
    I think I got it now :-)
    First: Show me priority all  delivery addresses . Otherwise billing addresses:
    SELECT T1.[CardCode], T2.[Street] FROM OCRD T1  INNER JOIN CRD1 T2 ON T1.CardCode = T2.CardCode WHERE NOT EXISTS
      SELECT *
      FROM CRD1 as T2
      WHERE T2.[AdresType] = 's' and t1.CardCode = t2.Cardcode
    union
    SELECT T1.[CardCode], T2.[Street] FROM OCRD T1  INNER JOIN CRD1 T2 ON T1.CardCode = T2.CardCode
    where T2.[AdresType] = 's'
    secondly:
    Filter all invoices by date, articles and show priority the delivery address else billingaddress and subtract the credits:
    SELECT T0.[Cardcode], T0.[CardName], T3.[ZipCode],T3.[Street], T1.[ItemCode], T1.[Dscription], T1.[ShipDate], T1.[Price], (T1.[Price] * T1.[Quantity]) as "Gesamtpreis in €", T1.[FreeTxt],substring(T1.Freetxt,0,5) as "Grundpreis in €",substring(T1.Freetxt,9,6) as "TS-Wert in %", T1.[Quantity]
    FROM OINV T0  INNER JOIN INV1 T1 ON T0.DocEntry = T1.DocEntry INNER JOIN OCRD T2 ON T0.CardCode = T2.CardCode INNER JOIN CRD1 T3 ON T2.CardCode = T3.CardCode
    WHERE CONVERT(nvarchar(8), T1.ShipDate, 112) BETWEEN '[%FromDate]' AND '[%ToDate]'
    and T1.Itemcode = [%0] and not exists  (
      SELECT *
      FROM CRD1 as T3
      WHERE T3.[AdresType] = 's' and t2.CardCode = t3.Cardcode
    GROUP BY T0.[Cardcode], T0.[DocNum],T0.[CardCode], T0.[CardName], T3.[ZipCode],T3.[Street], T1.[ItemCode], T1.[Dscription], T1.[ShipDate], T1.[Price], T1.[FreeTxt], T1.[Quantity]
    union
    SELECT T0.[Cardcode], T0.[CardName], T3.[ZipCode],T3.[Street], T1.[ItemCode], T1.[Dscription], T1.[ShipDate], T1.[Price], (T1.[Price] * T1.[Quantity]) as "Gesamtpreis in €", T1.[FreeTxt],substring(T1.Freetxt,0,5) as "Grundpreis in €",substring(T1.Freetxt,9,6) as "TS-Wert in %", T1.[Quantity]
    FROM OINV T0  INNER JOIN INV1 T1 ON T0.DocEntry = T1.DocEntry INNER JOIN OCRD T2 ON T0.CardCode = T2.CardCode INNER JOIN CRD1 T3 ON T2.CardCode = T3.CardCode
    Where T3.[AdresType] = 's' and T1.Itemcode = [%0] and CONVERT(nvarchar(8), T1.ShipDate, 112) BETWEEN '[%FromDate]' AND '[%ToDate]'
    -- ab hier werden die Gutschriften abgezogen
    union
    SELECT T0.[Cardcode], T0.[CardName], T3.[ZipCode],T3.[Street], T1.[ItemCode], T1.[Dscription], T1.[ShipDate], -T1.[Price], -(T1.[Price] * T1.[Quantity]) as "Gesamtpreis in €", T1.[FreeTxt], ('-' + substring(T1.Freetxt,0,5)) as "Grundpreis in €",substring(T1.Freetxt,9,6) as "TS-Wert in %", -T1.[Quantity] FROM ORIN T0  INNER JOIN RIN1 T1 ON T0.DocEntry = T1.DocEntry INNER JOIN OCRD T2 ON T0.CardCode = T2.CardCode INNER JOIN CRD1 T3 ON T2.CardCode = T3.CardCode WHERE CONVERT(nvarchar(8), T1.ShipDate, 112) BETWEEN '[%FromDate]' AND '[%ToDate]' and T1.Itemcode = [%0]
    and not exists  (
      SELECT *
      FROM CRD1 as T3
      WHERE T3.[AdresType] = 's' and t2.CardCode = t3.Cardcode
    GROUP BY  T0.[Cardcode], T0.[DocNum], T0.[CardName], T3.[ZipCode],T3.[Street], T1.[ItemCode], T1.[Dscription], T1.[ShipDate], T1.[Price], T1.[FreeTxt], T1.[Quantity]
    union
    SELECT T0.[Cardcode], T0.[CardName], T3.[ZipCode],T3.[Street], T1.[ItemCode], T1.[Dscription], T1.[ShipDate], T1.[Price], (T1.[Price] * T1.[Quantity]) as "Gesamtpreis in €", T1.[FreeTxt],substring(T1.Freetxt,0,5) as "Grundpreis in €",substring(T1.Freetxt,9,6) as "TS-Wert in %", T1.[Quantity]
    FROM OINV T0  INNER JOIN INV1 T1 ON T0.DocEntry = T1.DocEntry INNER JOIN OCRD T2 ON T0.CardCode = T2.CardCode INNER JOIN CRD1 T3 ON T2.CardCode = T3.CardCode
    Where T3.[AdresType] = 's' and T1.Itemcode = [%0] and CONVERT(nvarchar(8), T1.ShipDate, 112) BETWEEN '[%FromDate]' AND '[%ToDate]'

Maybe you are looking for

  • Error while importing on local files/queries from Sap Portal EP6

    Hi, When i try to import a file from sap portal to the local PC, I get a screen with the header "Enter Some File attributes". Text displayed in the screen is "Please wait. You will be forwarded automatically. This page had to be included for technica

  • Wm with qm interface  when the gr the quant is merging

    hi gurus. Store do GR, Material route for QA Inspection.  After QA Usage Decision make, WM post change number generated.  Material will be at 922-TR Zone interim area pending for post change to be completed. When there is another GR, QA Inspection an

  • JAX-WS newbie

    Hi All, I am new to web services. I am still learning. I want to know how to develop JAX-WS(metro webservices) using contract-first approach? I just read in Axis2 you can do it using wsdl2java. I may be wrong but what I read about wsimport in metro w

  • How to set a hotkey for a service in Finder

    Hi, I created a service for finder which works perfectly. Now I'm looking for a way to start it as quickly as fast as possible. I tried different hotkeys for it in settings > services but none of them works - when I press them in finder nothing happe

  • Save changes to a theme

    Is there a way to save the changes that you've made to a theme? I have created a podcast site and when I click new entry, it come up with the theme with the themes photo place holder. This means that I have to redo any changes that I have done to the