MYSQL select where field does not contain a certain string character
Asked Answered
B

3

7

I use sql to select all my sites URLs from a table.

$sql = 'select * from pages where "myURL field";

However I want to be a little more specific with my query. There are a few duplicate links in my table for example:

about-us
./about-us

I don't want the ./about us field to be selected. Is there a way of saying:

select * where "myURL field" does not begin with . /

Or should I just forget it and parse using PHP?

Bay answered 18/8, 2014 at 13:10 Comment(0)
O
14
SELECT * FROM pages WHERE some_col NOT LIKE './%';

This will fetch all rows where some_col is not starting with ./

Ole answered 18/8, 2014 at 13:12 Comment(1)
Works a treat, nice one : )Bay
D
3

Use LIKE in mysql to check that it is not starting with ./. Use the code below

SELECT * FROM pages WHERE col_name NOT LIKE './%';

Hope this helps you

Deficient answered 18/8, 2014 at 13:16 Comment(0)
M
0
select * from pages where my_url NOT LIKE './%';
Meatiness answered 18/8, 2014 at 13:18 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.