Select records like X% or Y%
914790Feb 17 2012 — edited Feb 17 2012Hi,
I am trying to maintain a list of users in my database.
-----------------------------------------------------------------
SQL> create table t1(name varchar2(10));
Table created
SQL> insert into t1 values ('Arnold');
1 row inserted
SQL> insert into t1 values ('Bob');
1 row inserted
SQL> insert into t1 values ('Cathy');
1 row inserted
SQL> insert into t1 values ('Bill');
1 row inserted
SQL> commit;
Commit complete
------------------------------------------------
Now I use the following query to identify users whose names start with 'B'
---------------------------------
SQL> select * From t1 where name like 'B%';
NAME
Bob
Bill
---------------------------------------------------------------
But, I am not sure how to identify users whose names start with 'B' or 'C'.
Although the following query will satisfy my requirement, please suggest if there is a better way to achieve this.
----------------
SQL> select * From t1 where name like 'B%'
+2 union+
+3 select * From t1 where name like 'C%'+
+4 ;+
NAME
Bill
Bob
Cathy
----------------