Separate date while joining

Hello

While the join of two tables and comparing with dates, I need to select the distinct value for example

table_1

col_1, col_2 date_1

1-2 JUNE 10, 2015

1-2 JUNE 11, 2015

table_2

col_1 start_date end_date

1 1 JANUARY 2015 DECEMBER 31, 2015

1 January 1, 2015 December 31, 2015

When I join I need only two records by comparing different start date and end date

output because the date_1 is down between the start date and end date of table_2

col_1, col_2 date_1

1-2 JUNE 10, 2015

1-2 JUNE 11, 2015

but by using the query get four records because of the join below

Select * from table_1 a, b table_2

where a.col_1 = b.col_1

and a.date_1 between b.start_date and b.end_date;

I think that if I use will come from this problem, but y at - it another option

Hello

944524 wrote:

Hello

While the join of two tables and comparing with dates, I need to select the distinct value for example

table_1

col_1, col_2 date_1

1-2 JUNE 10, 2015

1-2 JUNE 11, 2015

table_2

col_1 start_date end_date

1 1 JANUARY 2015 DECEMBER 31, 2015

1 1 JANUARY 2015 DECEMBER 31, 2015

When I join I need only two records by comparing different start date and end date

output because the date_1 is down between the start date and end date of table_2

col_1, col_2 date_1

1-2 JUNE 10, 2015

1-2 JUNE 11, 2015

but by using the query get four records because of the join below

Select * from table_1 a, b table_2

where a.col_1 = b.col_1

and a.date_1 between b.start_date and b.end_date;

When you join table_1 to table_2, if a given line of table_1 corresponds to N rows in table_2, then this line appears N times in the result set.

If you want a row of table_1 to appear (at most) 1 time in the result set, if it corresponds to lines 1, 2, 3 or in table_2, then maybe you don't want a join, especially since you need not all table_2 data in the result set.  An EXISTS subquery might be more appropriate to your limit.

For example:

SELECT *.

FROM table_1 t1

WHEN THERE IS)

SELECT 1

IN table_2 t2

WHERE t1.col_1 = t2.col_1

AND t1.date_1 BETWEEN t2.start_date

AND t2.end_date

)

;

There are ways to do this with a join, but they are probably less effective.  If you do a join, then, in fact, you do a query to produce more rows in the result set that you want, and then doing extra work to remove the lines that you don't want.  It is more effective if you generate all of the additional lines in the first place.

I hope that answers your question.

If this isn't the case, post a small example of data (CREATE TABLE and only relevant columns, INSERT statements) for all of the tables involved and the exact results you want from these data.

Point where the above query is to produce erroneous results, and explain, using specific examples, how you get the right results from data provided in these places.

If you change the query at all, post your modified version.

Always say what version of Oracle you are using (for example, 11.2.0.2.0).

See the forum Re: 2. How can I ask a question on the forums?

Tags: Database

Similar Questions

  • Use of data while you sleep at night

    Ill be sleep at night and wake up with a text saying I used data while he slept. I've got data unlimited, so it is a problem for me. I close my apps when all the time throughout the day and especially at night. I am connected to the Internet and considering all applications are closed that he shouldn't have to data. Ive already used 90% of my data and I have ten days he remains until Bill again.

    SO while he slept connected to Internet with NO open apps I use my data...

    heatherbarry wrote:

    Ill be sleep at night and wake up with a text saying I used data while he slept. I've got data unlimited, so it is a problem for me. I close my apps when all the time throughout the day and especially at night. I am connected to the Internet and considering all applications are closed that he shouldn't have to data. Ive already used 90% of my data and I have ten days he remains until Bill again.

    SO while he slept connected to Internet with NO open apps I use my data...

    If this text from your carrier, it does necessarily mean that data are used as you sleep. This may mean that the company will update its system at midnight (or another time), and then sends the message.

    "Closing" applications from the recent state bar has no effect on a large part of what whatsoever (unless the application does not work correctly). Generally, there is no reason to waste your time doing this.

    Check the settings > General > background App refresh and turn it off for all the apps you don't think you need to do the update when you are not using the. Disable notifications for the applications that you really need not notifications use data.

    Make sure you're phone is plugged into the night. If you have it turned on but not plugged in, the phone will return to cellular data once the screen goes to sleep.

  • In the attached VI why looping force the type of data while the other does not?

    In the attached VI why looping force the type of data while the other does not?

    I'm guessing that you have created the Enum on the front panel.  If you right click and create an indicator, it corresponds to the type and be an enum.  LabVIEW represents enums as U16, but because the types are not the same (for example, your enum has 3 values, but a U16's 65 536 values), LabVIEW automatically converts value (or converts) the smallest representation (enum) in the largest value (U16).

  • BlackBerry Blackberry Passport engulfed my data while I was asleep

    My BB Passport engulfed my data while I was asleep and I don't know if it was my camera or my carrier. I called my provider and they said: "Yes your data have been used 3-5 a.m." but they don't tell me how. They suggested that I look at my 'event log' of the phone to see if there was an update to the App. No such thing as 'event log' exists on a passport of Blackberry and the 'Usage.log' file which is generated from the BBlink is empty. Then, on my phone, data services is the position, but it is also connected to the Wifi, the automatic update is disabled and but there is no e-mail or any communication at all. I want to know how this fact happened to prevent it from happening again. My phone is as naked as it came in the BB store. No additional Apps or social media communications. I only use BBM when I am connected to wifi and I use the phone to check my emails (without attachments or anything like that) and make a few calls per month. It is therefore as important as if we actually stole my phone! Any ideas how to solve this problem?

    1 - the device must use wifi if (a) wifi is enabled, (b) there is a connection to a wifi network, and (c) there is a flow of data on the wifi network. If the mobile network is activated, if the data service is activated on the mobile network, and if there is a connection and flow, the unit will switch for mobile if it must. I have no way of knowing what happened or why, only that I'm not surprised.

    2. I don't know what in the stock device software. You can install to alert you, but I've never looked.

    3. I don't think that there is something that has changed.

    4. in the settings of mobile network, you can leave the mobile phone on any network turn off the data. Calls and SMS will work. Data and anything that uses data or any application that can only use mobile data won't work on the mobile network. But if the wifi is enabled, etc. it will be as data on wifi service.

    5 see #4

    6 seriously doubt

    7. I would like to purchase enough mobile data to well exceed what you're likely to use. If this is not possible, then that's a different issue and I know that you do what you have to do. But modern smartphones use a large amount of data for many reasons.

  • Remove the separate data container

    I'm trying to find how to change my package so that I can re build without a separate data container and without having to re capture, if possible. ?

    Please try the steps below:

    1. open the package.ini and find the section of the .dat under general purpose settings file. This section begins by [filename.dat]

    2 copy the below two lines of this section and stick them under the new section of the file that you want the data container

    ReadOnlyData = Package.ro.tvr
    MetaDataContainerOnly = 1

    3. delete the .dat file section
    4 find the row Source = filename.dat, you will see that in a lot of places in each file. Replace the value with the name of the new file in the world
    5 rebuild the package by running the build.bat file

    If there are difficulties, please download the package.ini and I can do for you.

  • Acccess filtered of measurement data, while the program is running?

    My main problem is that data that I take is 3-dimensional. I take measures of resistance, capacity and Q factor over a predetermined period of time, but the problem is that these measures are taken in a matrix of switching through provided pin code sequences.

    If I can take a measure of resistance from pin 1 to 20 pins between 10 am and I want a useful method for displaay these data to the user that the program is still collecting data. I write data to a TDMS file because it is collected, and the output format looks like this:

    My thoughts were going to have 4 separate controls that can be set to access specific aspects of the test while it is running to make this work. My idea is to have (4-6) something similar to the below:

    In this way the user can refine exactly what they are looking at in this case.

    Key question is whether I should / can:

    1) access to the PDM file for the information you selected with the commands above to fill the Microsoft graph chart?

    (2) the data measured in a wide range of stuff and then have sub - VI that filter of this large table to retrieve the data and complete the Microsoft graph chart?

    (3) another method...

    And advice have enjoyed. Thank you!

    ; How much data are you talking about?  Is - this low enough so that you would be able to keep the table in its entirety in the memory?  If so, then I would use your option 2.  Then design an interface that allows the user to determine what links they want to watch, and your program could analyze through this gathering the data and display it.

    If that's too much data, then you have to go with the PDM or another option of storing files and read the data back to the piecemeal and build your data table that applies to display.

  • Using "is" to obtain separate data...?

    Hello
    I have the following basic model {the real situation contains more tables...}. I want to get data separate unaided "distinct" or "unique", or "analytic function" or 'aggregate function' which are more or less the same in terms of performance...
    So, I tried the following using the above mentioned of the ways:
    /*1st version*/
    with 
    ms as
    (select 1 id, 'item_name1' item_name from dual
      union all
    select 2 id, 'item_name2' item_name  from dual
      union all
    select 3 id, 'item_name3' item_name from dual
      union all
    select 4 id, 'item_name4' item_name from dual
      union all
    select 5 id, 'item_name5' item_name from dual
      union all
    select 6 id, 'item_name6' item_name from dual) ,
    manufacturer as
    (select 10001 manufacturer_id, 'manufacturer_name1' name from dual
      union all
      select  10002 manufacturer_id, 'manufacturer_name2' name from dual
      union all
      select  10003 manufacturer_id, 'manufacturer_name3' name from dual
      union all
      select  10004 manufacturer_id, 'manufacturer_name4' name from dual),
      part_no as (select 10001 manuf_id, 1 item_id, '1090j-uy' part_number from dual
       union all
       select 10001 manuf_id, 1 item_id, '1090ji-10uy' part_number from dual
       union all
       select 10002 manuf_id, 2 item_id, '912-0io' part_number from dual
       union all
       select 10003 manuf_id, 3 item_id, null part_number from dual)
    select distinct ms.id, ms.item_name
       from ms
       left outer join (select name, item_id
                        from
                         manufacturer m
                        join part_no p
                          on m.manufacturer_id=p.manuf_id) man_partno
       on ms.id=man_partno.item_id;
    /*2nd version*/
    with 
    ms as
    (select 1 id, 'item_name1' item_name from dual
      union all
    select 2 id, 'item_name2' item_name  from dual
      union all
    select 3 id, 'item_name3' item_name from dual
      union all
    select 4 id, 'item_name4' item_name from dual
      union all
    select 5 id, 'item_name5' item_name from dual
      union all
    select 6 id, 'item_name6' item_name from dual) ,
    manufacturer as
    (select 10001 manufacturer_id, 'manufacturer_name1' name from dual
      union all
      select  10002 manufacturer_id, 'manufacturer_name2' name from dual
      union all
      select  10003 manufacturer_id, 'manufacturer_name3' name from dual
      union all
      select  10004 manufacturer_id, 'manufacturer_name4' name from dual),
      part_no as (select 10001 manuf_id, 1 item_id, '1090j-uy' part_number from dual
       union all
       select 10001 manuf_id, 1 item_id, '1090ji-10uy' part_number from dual
       union all
       select 10002 manuf_id, 2 item_id, '912-0io' part_number from dual
       union all
       select 10003 manuf_id, 3 item_id, null part_number from dual)
    select  ms.id, ms.item_name
       from ms
       left outer join (select max(name), item_id
                        from
                         manufacturer m
                        join part_no p
                          on m.manufacturer_id=p.manuf_id
                           group by item_id) man_partno
       on ms.id=man_partno.item_id;
    /*3rd version*/
    with 
    ms as
    (select 1 id, 'item_name1' item_name from dual
      union all
    select 2 id, 'item_name2' item_name  from dual
      union all
    select 3 id, 'item_name3' item_name from dual
      union all
    select 4 id, 'item_name4' item_name from dual
      union all
    select 5 id, 'item_name5' item_name from dual
      union all
    select 6 id, 'item_name6' item_name from dual) ,
    manufacturer as
    (select 10001 manufacturer_id, 'manufacturer_name1' name from dual
      union all
      select  10002 manufacturer_id, 'manufacturer_name2' name from dual
      union all
      select  10003 manufacturer_id, 'manufacturer_name3' name from dual
      union all
      select  10004 manufacturer_id, 'manufacturer_name4' name from dual),
      part_no as (select 10001 manuf_id, 1 item_id, '1090j-uy' part_number from dual
       union all
       select 10001 manuf_id, 1 item_id, '1090ji-10uy' part_number from dual
       union all
       select 10002 manuf_id, 2 item_id, '912-0io' part_number from dual
       union all
       select 10003 manuf_id, 3 item_id, null part_number from dual)
    select  ms.id, ms.item_name
       from ms
       left outer join (select rw, item_id, name
                        from
                        (
                        select row_number() over(partition by item_id order by name) rw,name, item_id
                        from
                         manufacturer m
                        join part_no p
                          on m.manufacturer_id=p.manuf_id
                        )
                        where rw=1
                           ) man_partno
       on ms.id=man_partno.item_id;
    I guess the way that would make the difference is the use of is... {or what.. I can't think another thing..!}, but I can't write it...
    /*desired...*/
    with 
    ms as
    (select 1 id, 'item_name1' item_name from dual
      union all
    select 2 id, 'item_name2' item_name  from dual
      union all
    select 3 id, 'item_name3' item_name from dual
      union all
    select 4 id, 'item_name4' item_name from dual
      union all
    select 5 id, 'item_name5' item_name from dual
      union all
    select 6 id, 'item_name6' item_name from dual) ,
    manufacturer as
    (select 10001 manufacturer_id, 'manufacturer_name1' name from dual
      union all
      select  10002 manufacturer_id, 'manufacturer_name2' name from dual
      union all
      select  10003 manufacturer_id, 'manufacturer_name3' name from dual
      union all
      select  10004 manufacturer_id, 'manufacturer_name4' name from dual),
      part_no as (select 10001 manuf_id, 1 item_id, '1090j-uy' part_number from dual
       union all
       select 10001 manuf_id, 1 item_id, '1090ji-10uy' part_number from dual
       union all
       select 10002 manuf_id, 2 item_id, '912-0io' part_number from dual
       union all
       select 10003 manuf_id, 3 item_id, null part_number from dual)
    select  ms.id, ms.item_name
       from ms
       left outer join (select name, p.item_id
                        from
                         manufacturer m
                        where exists (select item_id from
                                             part_no p
                                      where m.manufacturer_id=p.manuf_id
                           )) man_partno
       on ms.id=man_partno.item_id;
    Is there a way to get the desired result. ???

    Note: I use db10g v.2,
    Thank you
    SIM

    SIM,
    If you do not need the PART_NUMBER PART_NO table to the final result, the list of MANUF_ID and ITEM_ID separate (as I suggested before).
    If PART_NO table contains ITEM_ID even several times, you are processing several lines only to eliminate then AFTER treatment.

    WITH...
    ...
    select  ms.id, ms.item_name , man_partno.name
       from ms
       left outer join (select name, item_id
                        from
                         manufacturer m
                        join (select distinct t.MANUF_ID,T.ITEM_ID from part_no t) p
                          on m.manufacturer_id=p.manuf_id) man_partno
       on ms.id=man_partno.item_id;
    
    ID     ITEM_NAME     NAME
    2     item_name2     manufacturer_name2
    3     item_name3     manufacturer_name3
    1     item_name1     manufacturer_name1
    5     item_name5
    6     item_name6
    4     item_name4     
    

    VR,
    Sudhakar B.

  • DB connectivity Kit: syntax error in a SELECTION of data from joined tables

    Hello everyone

    I'm putting in labview a SQL query on joined tables.

    As an example I take a database to store the data of basketball 2on2 matches, which tables are

    corresponds to (matchId, Thomas, teamB)

    teams (teamId,PlayerAname, PlayerBname, nationality)

    nationalities (NatId, natName)

    To get an array of result with the game as well as the names of player as well as their nationality, I use this query on MySQL (which works on command line interface)

    SELECT MatchID,
    T1. PlayerAName, t1. PlayerBName, n1.natName,
    T2. PlayerAName, t2. PlayerBName, n2.natName
    MATCHES m
    INNER JOIN teams t1 ON t1.teamID = m.teamA
    INNER JOIN teams t2 ON t2.teamID = m.teamB
    INNER JOIN nationalities L1 ON n1.natID = t1.nationality
    INNER JOIN nationalities n2 ON n2.natID = t2.nationality

    When I put it in labview, using the block 'select data', I get a syntax error as shown in the attached screenshot.

    Am I something mistanking using the JOIN examples statements or aliases?

    Thanks in advance!

    The select VI is designed to be a simple way to select from a table. I doubt that he can do joins (and would not certainly need the 'FROM', even if it can). What you can do instead calls the query execute VI and give him the complete SQL query. I don't remember if it returns the data in the recordset object, so you must do so separately.

  • Read TXT and separate data

    Hello

    I have a problem...

    I have this TXT file

    T1 1 00000010 00000001 OutIn t1
    Ters 1 00110000 00000011 OutIn t2
    ggfd 1 00000001 and 00000010 OutIn t1
    T1 0 00000110 00000011 InOut t1
    0 00110100 00000011 t1t2 OutIn T2

    T1 1 tab... tab t1 CR LF

    I read this file in Labview and I reveal separate these data for type...

    Rank 1 in table [1] [1] T1 [1] [2] 1 Array [1], [3] 00000010 ecc...

    Array [2] [1] Ters

    THX

    If you reveal I sand photo and diagram

    Good bye


  • Separate data from line

    Hello

    How can we separate a line into two lines data? Here's my original data.
    +--------------+---------------------+---------------------+
    | Requested By |     Start_Dttm      |      End_Dttm       |
    +--------------+---------------------+---------------------+
    | John Doe     | Jun 06 2011 10:00PM | Jun 07 2011 02:00AM |
    +--------------+---------------------+---------------------+
    Out of desire, separate time to midnight fields.
    +--------------+---------------------+---------------------+
    | Requested By |     Start_Dttm      |      End_Dttm       |
    +--------------+---------------------+---------------------+
    | John Doe     | Jun 06 2011 10:00PM | Jun 07 2011 12:00AM |
    | John Doe     | Jun 07 2011 12:00AM | Jun 07 2011 02:00AM |
    +--------------+---------------------+---------------------+
    Thanks in advance :)

    Rather than to convert dates to strings, I think that it would be preferable to maintain the output of the query as dates...

    SQL> alter session set nls_date_format='Mon DD YYYY HH24:MI:SS';
    
    Session altered.
    
    SQL> ed
    Wrote file afiedt.buf
    
      1  WITH t AS (SELECT 'John Doe' requested_by
      2                   ,TO_DATE('06-JUN-2011 22:00', 'DD-MON-YYYY HH24:MI') start_dttm
      3                   ,TO_DATE('07-JUN-2011 02:00', 'DD-MON-YYYY HH24:MI') end_dttm
      4             FROM   dual)
      5  --
      6  -- end of test data
      7  --
      8  select requested_by
      9        ,greatest(start_dttm,trunc(start_dttm)+rownum-1) as start_dttm
     10        ,least(end_dttm,trunc(start_dttm)+rownum-(1/86400)) as end_dttm
     11  from t
     12* connect by rownum <= trunc(end_dttm)-trunc(start_dttm)+1
    SQL> /
    
    REQUESTE START_DTTM           END_DTTM
    -------- -------------------- --------------------
    John Doe Jun 06 2011 22:00:00 Jun 06 2011 23:59:59
    John Doe Jun 07 2011 00:00:00 Jun 07 2011 02:00:00
    

    I took the liberty to assume that the time of the end of a day would be at 11:58.

    In addition, it should be noted that Oracle does not have midnight as being 12 am. This is something that only a few applications need (for example, some cooks who go to 12:00 midnight, followed by 00:01, 1 minute later). Midnight in Oracle is 00:00:00

  • How can I find what is access to the Internet on the iPad (which runs 4 times a day) and using my data while traveling plan? Thank you

    My iPad access the internet 4 times per day (9 am/pm and 3 am/pm) and I need to know what it is and fix it as it uses all my data plan when you travel. Thank you

    A possibility: go to settings > cell phone and scroll down to "cell using data for. Under each name of app, it will show the amount of data used by this application since the last reset. You can reset the statistics at any time by scrolling all the way to the bottom of this screen and tapping reset statistics.

  • How to use a script to separate data in separate sheets?

    For example, sake, I have three columns: the food consumed (lbs), the Date and Pet (Fido, Penny, whiskers). I want to tease the data part as the data for the first two columns for Penny, Fido and whiskers all appear on different sheets.

    Thanks in advance

    Hi, FCW,.

    I created a use to read in your Excel data file - if you happen to have DIAdem 2010 (11.2) or later, you will be able to use it.  In the case otherwise just load the file but you were before loading so that your 4 data channels are the only ones in the data portal, then run the "DataFileWhisperer.VBS" script in the SCRIPT of DIAdem.

    Brad Turpin

    Tiara Product Support Engineer

    National Instruments

  • How to separate data in 'several Information.vi tone "?

    NOTE: I have another post on this subject. Here is the link.
    -----------------------------------------------------------------------------------

    My ultimate goal is to get/display of the frequency at which the peaks that passes.

    I've used different methods (vi is attached) but does not own.

    1 table of Max and Min > it only shows Max amplitude but not all orders of magnitude and not the frequencies at which the peaks that passes. I guess I should somehow use a search function in a loop or something, but I have no idea how to do that.

    2 peak detector of. VI > This method was good for the summits, but not the frequency. It shows the indexes that are double. If I multiply them by 10, it gives me the frequency and I don't know why?

    3. several information.vi tone > This method has the advantage of threshold, but it's the combination of the cluster and the table which I don't know how it unbundle and get the frequency. Another problem is that it shows only a single tip and its frequency to the not all same time as I develop the table.

    Thank you

    I have change your dynamic waveform data. Extract several tone Information.vi works better now.

    This function need a waveform as input.

    Concerning

  • Error prevention of execution of data while trying to play star trek online Facebook

    I received a Data Execution Prevention error when trying to load a Facebook game called "Star Trek Online" via a company called Perfect World.  Have you had problems with them before?  Is a data execution error a serious threat? This company via facebook was trying to infiltrate there PC or give a virus?  Thank you for your answers and the time.

    Hello Joseph,.

    I would suggest following the instruction in this article on the change Data Execution Prevention settings:
    There is also a FAQ on this subject:
  • B1500 read data while measuring

    Hello

    I'm trying to control my B1500A. I need to read some datas all B1500 measuring.

    All the drivers are provided with a reading after finished measurement. I cannot read the buffer before the end of the measure.

    does anyone know how to do this?

    Thank you very much

    Claire


Maybe you are looking for