Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Unusual query

Status
Not open for further replies.

tdion

MIS
Dec 18, 2003
61
US
This should be easy for someone who has been writing SQL statements for awhile.

I need to query for information in a table that looks similar to this:

SELECT field1 FROM table WHERE field2='123' OR field3 LIKE '456*' OR field3 LIKE '678*'

You can see the delimma with the statement. Field2 must be equals to '123' while field 3 can take either of the two LIKES. The way the statement reads, any records with field2 equaling '123' or field3 with the LIKES will be selected.

I need the statement to select either field2='123' and field3 LIKE '456*' .... or .... field2='123' and field3 LIKE '678*'

Thanks for your help.

 
SELECT field1 FROM table WHERE (field2='123') AND (field3 LIKE '456*' OR field3 LIKE '678*')

OR You can also Try

SELECT field1 FROM table WHERE (field2='123') AND (field3 LIKE '456%' OR field3 LIKE '678%')

Hope That helps.

VJ
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top