Select query problem

select from where like a% or b%

Page 1 of 1

9 Replies - 1045 Views - Last Post: 20 August 2009 - 05:49 AM Rate Topic: -----

#1 b.ihde  Icon User is offline

  • D.I.C for life
  • member icon

Reputation: 44
  • View blog
  • Posts: 1,070
  • Joined: 29-September 08

Select query problem

Posted 19 August 2009 - 07:16 AM

Hi,

well i don t even know if this is possible^^

I want to show all data which starts with "a" and "b"... So..

My query so far:

SELECT Lastname, Firstname FROM Persons WHERE Lastname LIKE 'a%'

Thanks for helping me out!


Ben
Is This A Good Question/Topic? 0
  • +

Replies To: Select query problem

#2 ForcedSterilizationsForAll  Icon User is offline

  • D.I.C Addict

Reputation: 33
  • View blog
  • Posts: 506
  • Joined: 16-July 09

Re: Select query problem

Posted 19 August 2009 - 07:24 AM

Look into the union statement.
Was This Post Helpful? 1
  • +
  • -

#3 b.ihde  Icon User is offline

  • D.I.C for life
  • member icon

Reputation: 44
  • View blog
  • Posts: 1,070
  • Joined: 29-September 08

Re: Select query problem

Posted 19 August 2009 - 07:33 AM

Ah found it! Thanks a lot!
Was This Post Helpful? 0
  • +
  • -

#4 xerxes333  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 31
  • View blog
  • Posts: 504
  • Joined: 05-July 07

Re: Select query problem

Posted 19 August 2009 - 09:54 AM

Rather than adding the overhead of a union why not just try

SELECT Lastname, Firstname FROM Persons WHERE Lastname LIKE 'a%' or Lastname LIKE 'b%'



EDIT: conditional change

This post has been edited by xerxes333: 19 August 2009 - 09:54 AM

Was This Post Helpful? 0
  • +
  • -

#5 ForcedSterilizationsForAll  Icon User is offline

  • D.I.C Addict

Reputation: 33
  • View blog
  • Posts: 506
  • Joined: 16-July 09

Re: Select query problem

Posted 19 August 2009 - 10:42 AM

View Postxerxes333, on 19 Aug, 2009 - 08:54 AM, said:

Rather than adding the overhead of a union why not just try

SELECT Lastname, Firstname FROM Persons WHERE Lastname LIKE 'a%' or Lastname LIKE 'b%'



EDIT: conditional change



Based on how big the table is and what fields are indexed, the OR statement can add a lot of overhead, especially when dealing with the LIKE statement.

Try running both and looking at the execution plans. I know we've had issues where using the OR statement caused queries to run quite a bit longer than using a UNION statement.
Was This Post Helpful? 0
  • +
  • -

#6 xerxes333  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 31
  • View blog
  • Posts: 504
  • Joined: 05-July 07

Re: Select query problem

Posted 19 August 2009 - 11:19 AM

View PostForcedSterilizationsForAll, on 19 Aug, 2009 - 11:42 AM, said:

. . .
Try running both and looking at the execution plans. I know we've had issues where using the OR statement caused queries to run quite a bit longer than using a UNION statement.



:^: Agree test both and see which is more efficient
Was This Post Helpful? 0
  • +
  • -

#7 b.ihde  Icon User is offline

  • D.I.C for life
  • member icon

Reputation: 44
  • View blog
  • Posts: 1,070
  • Joined: 29-September 08

Re: Select query problem

Posted 20 August 2009 - 05:26 AM

For me, the first soloution is the best way :)

Thank you both!
Was This Post Helpful? 0
  • +
  • -

#8 TheGame1083  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 44
  • Joined: 20-July 09

Re: Select query problem

Posted 20 August 2009 - 05:30 AM

how do u make the source code all colorful??

cause I always put my code between
 and 


and it always comes out black
Was This Post Helpful? 0
  • +
  • -

#9 b.ihde  Icon User is offline

  • D.I.C for life
  • member icon

Reputation: 44
  • View blog
  • Posts: 1,070
  • Joined: 29-September 08

Re: Select query problem

Posted 20 August 2009 - 05:39 AM

Look at the name of the box... :)

it s not code, it s sql
Was This Post Helpful? 0
  • +
  • -

#10 TheGame1083  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 44
  • Joined: 20-July 09

Re: Select query problem

Posted 20 August 2009 - 05:49 AM

can u help me with this Topic post i did

Report Viewer in C#

just do a search for that name
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1