Working with a complex query and trying to get rid of duplicates

I'm working with the following complex query, and I need to
select vin, number, year, make, model, and state from
2007 vehicles in certain models, vin types
2006 vehicles in certain models, vin types
Is there a more efficient way to write this than how I've been writing it?:
select distinct vehicle.vin VIN, unit.STATION_ID STID, unit.EMBEDDED_AREA_CODE||unit.EMBEDDED_PREFIX||lpad(unit.EMBEDDED_RON,4,0)
MIN, unit.AUTHENTICATION_ID AUTHCODE, vehicle.user_veh_desc, veh_model.VEH_MODEL_DESC MODEL, veh_model.VEH_MANUF_YEAR YEAR, acct_veh.STATE STATE
from vehicle
inner join veh_unit on vehicle.vehicle_sak=veh_unit.vehicle_sak
inner join unit on veh_unit.unit_sak=unit.unit_sak
inner join vdu_profile on vdu_profile.vehicle_sak=vehicle.vehicle_sak
inner join vdu_profile_program on vdu_profile_program.VDU_PROFILE_SAK=vdu_profile.VDU_PROFILE_SAK
inner join veh_model on vehicle.VEH_MODEL = veh_model.VEH_MODEL
inner join acct_veh on acct_veh.VEHICLE_SAK = vehicle.VEHICLE_SAK
and vehicle.user_veh_desc like ('%2007%')
AND unit.unit_gen_id >= 36
AND vdu_profile_program.VDU_PROGRAM_SAK = 3
and vdu_profile_program.PREFERENCE_VALUE = 'Y'
and acct_veh.STATE in ('MN','ND','IA')
AND (veh_model.VEH_MODEL_DESC like ('%Vehicle2%')
OR veh_model.VEH_MODEL_DESC like ('%Vehicle3%')
OR veh_model.VEH_MODEL_DESC like ('%Vehicle5%')
OR veh_model.VEH_MODEL_DESC like ('%Vehicle6%')
OR veh_model.VEH_MODEL_DESC like ('%Vehicle7%')
OR veh_model.VEH_MODEL_DESC like ('%Vehicle8%')
OR veh_model.VEH_MODEL_DESC like ('%Vehicle9%'))
and ACCT_VEH.ACCT_VEH_STATUS_ID = 'A'
and (vehicle.vin like ('_______3_________')
or vehicle.vin like ('_______W_________')
or vehicle.vin like ('_______K_________')
or vehicle.vin like ('_______0_________'))
UNION
select distinct vehicle.vin VIN, unit.STATION_ID STID, unit.EMBEDDED_AREA_CODE||unit.EMBEDDED_PREFIX||lpad(unit.EMBEDDED_RON,4,0)
MIN, unit.AUTHENTICATION_ID AUTHCODE, vehicle.user_veh_desc, veh_model.VEH_MODEL_DESC MODEL, veh_model.VEH_MANUF_YEAR YEAR, acct_veh.STATE STATE
from vehicle
inner join veh_unit on vehicle.vehicle_sak=veh_unit.vehicle_sak
inner join unit on veh_unit.unit_sak=unit.unit_sak
inner join vdu_profile on vdu_profile.vehicle_sak=vehicle.vehicle_sak
inner join vdu_profile_program on vdu_profile_program.VDU_PROFILE_SAK=vdu_profile.VDU_PROFILE_SAK
inner join veh_model on vehicle.VEH_MODEL = veh_model.VEH_MODEL
inner join acct_veh on acct_veh.VEHICLE_SAK = vehicle.VEHICLE_SAK
and vehicle.user_veh_desc like ('%2006%')
AND unit.unit_gen_id >= 36
AND vdu_profile_program.VDU_PROGRAM_SAK = 3
and vdu_profile_program.PREFERENCE_VALUE = 'Y'
and acct_veh.STATE in ('MN','ND','IA')
AND (veh_model.VEH_MODEL_DESC like ('%Vehicle1%')
OR veh_model.VEH_MODEL_DESC like ('%Vehicle2%')
OR veh_model.VEH_MODEL_DESC like ('%Vehicle3%')
OR veh_model.VEH_MODEL_DESC like ('%Vehicle4%')
OR veh_model.VEH_MODEL_DESC like ('%Vehicle5%')
OR veh_model.VEH_MODEL_DESC like ('%Vehicle6%')
OR veh_model.VEH_MODEL_DESC like ('%Vehicle7%'))
and ACCT_VEH.ACCT_VEH_STATUS_ID = 'A'
and (vehicle.vin like ('_______Z_________')
or vehicle.vin like ('_______K_________'))

I am not sure how many rows you have in the tables but I am assuming that there would be performance benefits in performing the query only once. You can combine similar coding and use an OR condition for the parts that are different. I left the 'K' vin comparison in both years for readability.
I was not able to fully test my code but I believe that it will work as is. I hope it helps. If you are happier with the UNION you may want to investigate the WITH clause as you can query a subset of data twice, rather than the full data set.
-- Common code 
SELECT DISTINCT
   vehicle.vin,
   unit.station_id stid,
   unit.embedded_area_code || unit.embedded_prefix || LPAD (unit.embedded_ron, 4, 0) MIN,
   unit.authentication_id authcode,
   vehicle.user_veh_desc,
   veh_model.veh_model_desc model,
   veh_model.veh_manuf_year YEAR,
   acct_veh.state
FROM vehicle
INNER JOIN veh_unit           
   ON vehicle.vehicle_sak = veh_unit.vehicle_sak
INNER JOIN unit               
   ON veh_unit.unit_sak = unit.unit_sak
INNER JOIN vdu_profile        
   ON vdu_profile.vehicle_sak = vehicle.vehicle_sak
INNER JOIN vdu_profile_program
   ON vdu_profile_program.vdu_profile_sak = vdu_profile.vdu_profile_sak
INNER JOIN veh_model          
   ON vehicle.veh_model = veh_model.veh_model
INNER JOIN acct_veh           
   ON acct_veh.vehicle_sak = vehicle.vehicle_sak     
AND unit.unit_gen_id >= 36
AND vdu_profile_program.vdu_program_sak = 3
AND vdu_profile_program.preference_value = 'Y'
AND acct_veh.state IN ('MN', 'ND', 'IA')
AND acct_veh.acct_veh_status_id = 'A'
AND
-- Annual code
      (   -- 2006 conditions 
      AND vehicle.user_veh_desc LIKE ('%2007%')
      AND regexp_like(veh_model.veh_model_desc, 'Vehicle[2356789]')
      AND regexp_like(vehicle.vin, '_{7}[3WK0]_{9}')           
   OR
      (   -- 2007 conditions 
      AND vehicle.user_veh_desc LIKE ('%2006%')
      AND regexp_like(veh_model.veh_model_desc, 'Vehicle[1234567]')
      AND regexp_like(vehicle.vin, '_{7}[ZK]_{9}')
   ).

Similar Messages

  • I am having trouble with my hotmail emails and want to get rid of them and start to use icloud emails instead.  Is this possible?

    I am having problems with my hotmail and live emails and want to cancel them and use icloud email instead, is this possible and how do I do it by creating icloud emails, and using icloud emails

    See the link below for how to sign up for and set up an iCloud account, including an @icloud.com email address:
    http://www.apple.com/icloud/setup/
    You'll need to update your Mac OS to 10.7.5 or later.

  • I have a new MacBook Pro. While getting rid of voice over I ended up with a black box with icons in it and I cannot get rid of it and I can't get off the home screen

    I have a brand new MacBook Pro . I got into voice over and then figured out how to stop that but now have a black box in the middle of the home screen and that box has a bunch of icons .....(Keyboard, pointer etc) I cannot get it to close and I'm not able to go past the home screen.  Help

    If you click on that window, the menu bar should change to whatever program that is. Then click the program name and click Exit.
    If that doesn't work, click the Apple icon, then Force Quit. Look for something that says Not Responding and quit it.
    Last... if nothing else works reboot and see if that does it.

  • Hi all, i can't sync over wifi between my iPhone 4 and Windows 7 64 bit, wifi sync works with the same phone and my Windows 8 machine, tried solutions from other threads with no luck, just thought i'd see if anyone else had any ideas, thanks.

    Hi all, i can't sync over wifi between my iPhone 4 and Windows 7 64 bit, wifi sync works with the same phone and my Windows 8 machine so the problem seems confined to Windows 7. I've tried solutions from other threads -
    Making sure everything is allowed through firewall
    Rebooting phone/laptop/router
    Disabling ipv6
    Disabling all networks except the one curently on
    Re-installing iTunes
    Restoring iPhone
    No luck with any of those unfortunately so i just thought i'd see if anyone else is still without wifi sync after trying those as well and if you ever found a fix, thanks.

    I just wanted to leave a note that it's working now. I'm not sure if it was the latest iTunes update that got it working or that i decided to start a new library instead of using the one i had backed up on Windows 8 (it didn't occur to me to check using the old library when i re-installed iTunes). But if anyone is having this problem, it might be worth trying again with a new installation of iTunes to see if the latest update works for you, and if not, try using a fresh library instead of a backup (by fresh library i mean discard your old library completely and start a new library, not just restore as new iPhone, a whole new library).

  • My iPhone 5c sound/speaker only works with the headphones in and when I'm trying to change a ringtone in settings..

    my iPhone 5c sound/speaker only works with the headphones in and when I'm trying to change a ringtone in settings.. why is this?! its not on airplane mode, its not on silent, ive tried turning it on and off, software is up-to-date etc. just no sound for text alerts or when trying to play music/videos. Help!

    same issue as this guy it's a hardware issue
    https://discussions.apple.com/thread/6266690?tstart=0

  • Trying to set up a linksys router but the cd says it works with OSX 10.6 and later. I am currently running the newest version of mountain lion.... what is the matter with this OSX   update needed?

    trying to set up a linksys router but the cd says it works with OSX 10.6 and later. I am currently running the newest version of mountain lion.... what is the matter with this OSX   update needed?

    Your install disk must look like this
    and not like this.
    Those gray disks are machine specific and will only work with model of Mac that they shipped with.

  • I changed my sim on my iPhone n reconfigured iMessage, it configured with my number but when i sign in with my apple id it says username/password is wrong while in all other things like FaceTime, App Store it worked with the same id and password

    i changed my sim on my iPhone n reconfigured iMessage, it configured with my number but when i sign in with my apple id it says username/password is wrong while in all other things like FaceTime, App Store it worked with the same id and password..
    can anyone help me to solve this issue

    i just opened my ipad, started my apple account/I.D. and realized I put the wrong e mail. I was having trouble correcting my I.D on the Ipad so I went to my laptop and make the proper changes/slash e mail address I wanted for my apple ID. I got back to my ipad and try to download an app I can't because I have to sign in my apple account and I can't because it still has the irrelivant I.D/email address..
    So, i did what you said.. went to setting>app store> tapped on my e mail.. it asked me to sign in (with my invalid emails address showing). I signed in with the password I had created. It said "incorrect".. I went to reset password. I reset password, tried to sign in and it says again "unvalid password".. this is getting irritating.  I have been asking and no one knows what to do.

  • Lync Server 2010 conference not working with Windows 8.1 and IE 10

    Hello,
    The problem is that whenever a Windows 8.1 user tries to join a Lync server 2010 conference using Internet Explorer 10 (or 11, tried that too) the user can't join the conference. If the conference is created by a Lync server 2013 user joining works fine.
    When using Lync 2010 client we get the following error in the client: "error id 87 source id 7".
    When using Lync 2013 client we end up with a blank conversation window.
    There are no traces in server log, client log or event log.
    Below is a set of use cases that may help you to understand what is the problem scenario. Each of these works or does not work with both Lync 2010 and Lync 2013 client.
    - Lync server 2010 conference, windows 7, Chrome, Firefox, IE 10 or 11 --> Works.
    - Lync server 2010 conference, windows 8.1, IE 10 or 11 --> Does not work.
    - Lync server 2010 conference, windows 8.1, Chrome or Firefox --> Works.
    - Lync server 2013 conference, windows 8.1, Chrome, Firefox, IE 10 or 11 --> Works.
    It does not help to add the meet address to IE compatibility list (Compatibility View Settings).
    If i press F12 in IE and change the document mode of the meet page to IE 9 version then i can join meetings with Windows 8.1 and IE 10. Unfortunately i cannot make that as a default setting for the meet website.
    Any ideas on how to get Lync server 2010 meetings working with Windows 8.1 and IE 10 or 11?
    IE is the company default browser. Windows 8.1 is not a default operating system but we have increasing number of Windows 8.1 computers in our environment (mainly directors).

    According to your description, it is hard to tell whether the issue is related with IE or Lync Server 2010 or both.
    Compare the log when Lync client on Window 8.1 with IE 10 or IE 11 join Lync server 2010 conferencing and Lync Server 2013 conferencing.
    Lisa Zheng
    TechNet Community Support

  • Reader X : Wrong Fonts (was working with Reader\Pro 9 and Pro 10)

    Hi all,
    First : this form pdf work with adobe Reader 9 and Acrobat Pro 9\X
    i did a pdf form with scribus, i embed 2 fonts : 3of9barcode and freemono bold fonts.
    (compatibility PDF 1.5 (acrobat 6) )
    My client update to Reader X and the problem is that the fonts are 'squares' and the barcode is text not barcode.
    When i do look at the properties in reader X, it founds the embedded fonts. There is no error when opening it.
    no console errors or Reader error.
    If i open the document with Pro X , there is no problem, the fonts are good. i try to save a copy, an optimized copy, or a copy with limited rights,
    but the result is the same, when i open the pdf with Reader X the fonts are bad.
    i tried ton install the fonts on Windows but it does not help...
    Do you have any clue ???

    I have exactly the same problem!!!
    I create and layout my forms in scribus and adjust them in Adobe 9 Pro. Setting the tab order and having the possibility to make fillable forms saveable are gorgeous. However, people who use ReaderX cannot work with these very forms anymore because there appears only squiggly squary rubbish in the fillable form fields instead of nice and clean Times Now Roman font. In Reader 9 everything worked fine. I cannot force everybody to go back to version 9, in order to be able to work wth the forms.
    It's so annoying, please help.

  • I've been working with documents in pages and recently downloaded word for mac. i open the pages documents and they appear to be corrupt. at least, a lot of the font is now in weird boxed pictures. what do i do?

    I've been working with documents in Pages and recently downloaded Word for Mac. Upon opening Pages documents with Pages, the documents appear corrupt. Much of the font has been replaced with boxed little pictures - yet they are identified as times new roman. What do I do?

    You got the new iphone?????   I have same problem.  I transferred audiobooks to device to find no audiobooks on device (despite it being in iTunes as if it was).  Have you found a solution?????   I even tried to change import settings on format transfer but hasn't worked. 

  • I am new to working with pdf.  I am trying to fill out a form that was attached to a web site.  I have a Macbook Pro.  I am just learning Acrobat.  How do I get the form to accept input?

    I am new to working with pdf.  I am trying to fill out a form that was attached to a website.  I have a Macbook Pro and I am trying to learn Acrobat.  How do I get the form to accept my input?

    If there are Acrobat PDF form fields, not jus a space for a form field, then you will have to add them. It would be better to ask the provider of the form to add the fields. If you cannot add the fields, then you can use the add text feature.
    Have you looked in the "Tools" panel for the "Forms" category?
    Try Acrobat Users Community Tutorials , http://acrobatusers.com/tutorials.
    See Adobe TV - Acrobat, http://tv.adobe.com/channel/how-to/acrobat-xi-tutorials/.

  • Does 'versions' work with microsoft word, ppt and excel or just pages, keynote and numbers?

    Does 'versions' work with microsoft word, ppt and excel or just pages, keynote and numbers? I tried to do what the videos say but the little icon for versions is not there on word. Does this mean it only works for pages etc... or do i have to activate it somehow? If it is only for pages then this ***** and should be better advertised!!!

    Each application will need to be updated to work with Versions, Full Screen, and other Lion-specific features.

  • My IPhone's volume is not working. I have checked and tried everything. When I use my headset I can hear when phone rings or receive text msg when I pull the jack out I have no sound on anything

    My IPhone's volume is not working. I have checked and tried everything. When I use my headset I can hear when phone rings or receive text msg when I pull the jack out I have no sound on anything

    I had this problem with my 4s a couple of times when I'd taken the headphones out and it hasn't registered it. My solution was easy, all I had to do was turn the phone off and then on again.
    Although I'm sure you've already tried this its a sometimes forgotten and very easy solution to a lot of problems. I hope you find out what's wrong.

  • Working with PRIOR XY stage and Piezo stage

    Hi,
    I'm having a problem working with my XY stage and piezo stage of PRIOR.
    I have the 'Top-Level' example.
    As I was told from PRIOR I have to daizy-chaned the 2 controllers. I try to work with the piezo stae with automatic initiation but I gen an error.
    Does someone know how to work this out?
    Thank you
    Yoli

    Hi Marti,
    Thank you for replaying.
    Im trying to open the Piezo z with active x  using automation Open vi of LabView. The same as in top level forIZOpen but instead Im using PRIORLib.IPiezo.
    The error I'm getting is  3005:
    Automation Open: Object specified is not creatable in IPiezoOpen.vi 
    IPiezoOpen is the name I gave to the vi. (Attached ).
    As I was instructed the piezoZ controller in connected to the XY in daisy chained. So running top level, there is no problem controlling the XY stage. My problem is to activate and control the piezo.
    Also attached is the top level vi
    Thank you
    Attachments:
    piezoZ.doc ‏24 KB
    TopLevel.vi ‏117 KB

  • Only one of my earbuds on my bose headphones works with my ipad, iphone and macbook- if I hold them there the right earbud will work, but for the life of me, I can't get them to both work. Why is this? And is Apple doing anything about this?

    Only one of my earbuds on my bose headphones works with my ipad, iphone and macbook- if I hold them there the right earbud will work, but for the life of me, I can't get them to both work. Why is this? And is Apple doing anything about this? While Apple's headphones have (finally) admittedly gotten better of late, I still prefer the much more comfortable headphones & sound quality that Bose makes and that I spent the money for.

    Bose Product Support

Maybe you are looking for

  • Jmx Services as Business Services ?

    I am wondering if JMX service are just for managing or even suitable to use as business services. In my new work all remote (business) service invocation is done by using jmx services which i find rather freaky. The people there come from implementin

  • OES11SP1 LDAP issue on a node

    Hi, I have a 2 node cluster that we have upgraded from OES11 to OES11 sp1 at the beginning of august Last week we create a new ressource on the primary node (let's say NODE 1), but when we want to migrate this new ressource to the other node (let's s

  • My music app has a little glitch in it. needs to be fixed!!

    When i want to peacefully hear music, I click on a song. then, it skips two songs and immediatly go to the playlist. i try ALL the other songs but the same things happen!! please help!!

  • Performance Management EhP4 Issue 7

    Is there a possibility of doing moderation on a completed (or closed) appraisal document?

  • CS4 brush tool is a few pixels off

    Hello. In CS3 when I used the brush tool to clean up masks, I could put the edge of the round cursor on the edge of the subject at hand, and when I clicked the mouse, the brush would land right where I placed the cursor. Now, in CS4, the brush mark e