Programming Forums

Programming Forums (http://www.programmingforums.org/forumindex.php)
-   Other Programming Languages (http://www.programmingforums.org/forum38.html)
-   -   Sql Select (http://www.programmingforums.org/showthread.php?t=15602)

Logical1 Apr 12th, 2008 10:28 PM

Sql Select
 
Hello

How do you querry and find records where specific characters are present in the string in a specific column.
I did not find a better place to post this question so here it is:
I have a column (FirstColumn) in my table with string values such as:
D2-L4-X1
D3-L4-X4
D9-L8-X9
SELECT * FROM tblListing WHERE FirstColumn = 'L4'
would not work. I tried LIKE that did not work either.
How would you do this querry?
Thanks a million in advance.

Ancient Dragon Apr 12th, 2008 11:23 PM

Re: Sql Select
 
Did you try this: here

WHERE substring(FirstColumn,0,2) = 'L4'

or this depending on the implenmentation of SQL

WHERE substr(FirstColumn,0,2) = 'L4'

Jimbo Apr 13th, 2008 3:41 AM

Re: Sql Select
 
did you try something like SELECT * FROM tlbListing WHERE FirstColumn LIKE '%F4%'?

Ooble Apr 13th, 2008 10:54 AM

Re: Sql Select
 
Wouldn't you be better off here with two tables? tblListing can link to another table which contains the same ID and multiple FirstColumns.
:

tblListing:
ID | RandomColumn | OtherColumn
---+--------------+------------
 1 |          46 |        910
 2 |        9295 |          11
 3 |            7 |        125

tblFirstColumn:
ID | FirstColumnPart
---+----------------
 1 | D2
 1 | L4
 1 | X1
 2 | D3
 2 | L4
 2 | X4
 3 | D9
 3 | L8
 3 | X9


Then you can do this:
:

SELECT tblListing.* FROM tblListing, tblFirstColumn WHERE tblListing.ID = tblFirstColumn.ID AND tblFirstColumn.FirstColumnPart = 'L4'

Logical1 Apr 13th, 2008 3:40 PM

Thank you guys
 
Thank you guys I tried all your suggestions and each one worked.
Coffee shuld be on me!


All times are GMT -5. The time now is 4:04 AM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC