0

How to remove the letters between the first two letters and the last two letters? Is it something like a combination of LIKE and =<> ?

Table Name: Items_ordered

OrderDate      Item
------------------------
2015-07-01     Skateboard
2015-07-01     Life Vest
2015 -07-06    Parachute
2015-07-27     Umbrella   

Sample Output:

OrderDate      Item
--------------------
2015-07-01     Skrd
2015-07-01     List
2015-07-06    Pate
2015-07-27     Umla   
Hunter McMillen
  • 59,865
  • 24
  • 119
  • 170
  • 2
    Welcome to [so]! At this site you are expected to try to **write the code yourself**. After **[doing more research](//meta.stackoverflow.com/questions/261592)** if you have a problem you can **post what you've tried** with a **clear explanation of what isn't working** and providing a [**Minimal, Complete, and Verifiable example**](//stackoverflow.com/help/mcve). I suggest reading [ask] a good question and [the perfect question](http://codeblog.jonskeet.uk/2010/08/29/writing-the-perfect-question/). Also, be sure to take the [tour] and read **[this](//meta.stackoverflow.com/questions/347937/)**. – John Conde Jul 28 '17 at 12:49
  • 2
    Your google search string is `MySQL string functions`. – Dan Bracuk Jul 28 '17 at 12:51
  • Look this question: https://stackoverflow.com/questions/986826/how-to-do-a-regular-expression-replace-in-mysql – Daria Pydorenko Jul 28 '17 at 12:55
  • 1
    @DariaPydorenko Doesn't quite warrant a regexp – JohnHC Jul 28 '17 at 12:56

1 Answers1

1

Use left() and right()

select OrderDate, concat(left(Item,2), right(Item,2) )as NewItem
from Items_ordered

However, what happens with an item like 'Bag', with less than 4 letters?

JohnHC
  • 10,935
  • 1
  • 24
  • 40
  • Please don't post answers on obviously off-topic questions! See: **[Should one advise on off topic questions?](//meta.stackoverflow.com/q/276572/1768232)** Off-topic questions can be closed and deleted, which could nullify your contribution. – John Conde Jul 28 '17 at 12:56
  • @JohnConde I disagree that this is not MCVE. OP has explained table structure and desired output and has shown some level of what they tried – JohnHC Jul 28 '17 at 12:59
  • Where do they show what they've tried? There literally is no SQL in their question nor do they describe what they tried. – John Conde Jul 28 '17 at 13:17