basically, i need a query that looks mostly like this...
SELECT column FROM tablename WHERE column LIKE '%images/uploads%';
There only catch here is, that I only want a return where anything after uploads is ok as long as it's NOT a forward slash /
So, images/uploads/somethingelse is NOT what i'm looking for
images/uploadssomethingelse IS what i'm looking for.
Any ideas?
Thanks!
This would help you
SELECT column FROM tablename WHERE column LIKE '%images/uploads%' AND column NOT LIKE '%images/uploads/%';`
SELECT column
FROM tablename
WHERE
column LIKE '%images/uploads%'
and column not like '%images/uploads%/%';
SELECT column FROM tablename WHERE column REGEXP 'images/uploads[^/]*$';
Related
just as the question can we do something to get the length and first 3 characters of the employee name of one column
Please do not mark as answered or duplicate
i have the test tomorrow Advance SQL so I am trying to solve some imp question..
Please answer the problem
thanks again
Hi Shanu, You can use LEN() or LENGTH()(in case of oracle sql) function to get the length of a column.
SELECT LEN(column_name) FROM table_name;
And you can use SUBSTRING or SUBSTR() function go get first three characters of a column.
SUBSTRING( string, start_position, length );
SELECT SUBSTRING( column_name, 1, 3 ) FROM table_name;
To get both together use concatenation operator,
SELECT LEN(column_name)||SUBSTRING( column_name, 1, 3 ) FROM table_name;
Hope you got what you need. Any issues, feel free to ask
We can use SUBSTRING or SUBSTR() function, go get first three characters of a column.
And then try this particular query:
SELECT SUBSTRING(ename,1,3)
FROM emp;
Select len(ename) as Column_Length, left(ename,3) first_three_char from employee; ---------need to code your query. Should not use test format, will be confusing
You can also use substring function instead of left. Query will look like
Select len(ename) as Column_Length,substring(ename,1,3) first_three_char from employee;
SELECT LEN(EMPLOYEE_NAME),LEFT(EMPLOYEE_NAME,3) FROM EMPLOYEE_TABLE;
I'm trying to select all rows that contain only specific alphanumeric characters in MySQL using:
SELECT * FROM table WHERE column LIKE '%abc%' OR column LIKE '%abd%'
OR column LIKE '%ab%'
For instance:
abc1234 is ok
abd1234 is ok
abe1234 is not ok
abg4567 is not ok
ab1234 is ok
ac1234 is not ok
The problem is, it select all the "abe","abg". How to select abc1234, abd1234 and ab1234?
With this
OR column LIKE '%ab%'
As part of the WHERE clause, it's no surprise that abe and abg are selected.
Please permit me to also mention that queries LIKE '%something%' cannot make use of any indexes and are likely to be very slow on large tables. The fact that you have three of them in one query is only going to make it worse.
Use the below Query which will also use indexes on column column
SELECT * FROM table WHERE column LIKE 'ab%' AND column not LIKE 'abe%'
AND column not LIKE 'abg%'
The Reason the indexes will be used in this case is the query is not using wildcard in the beginning of the string literal
Remove the last part of your query, it is telling it to select abg and abe.
You have told it to select all items beginning with anything and ending with anything providing ab is in the middle.
Because column LIKE '%ab%' will get "abe" or "abg"
If you want number after "ab", this is your query:
SELECT * FROM table WHERE column LIKE '%abc%' OR column LIKE '%abd%'
OR column LIKE '%ab0%' OR column LIKE '%ab1%' OR column LIKE '%ab2%' OR column LIKE '%ab3%' OR column LIKE '%ab4%' OR column LIKE '%ab5%' OR column LIKE '%ab6%' OR column LIKE '%ab7%' OR column LIKE '%ab8%' OR column LIKE '%ab9%'
Are you going to select column contain "abc" or "abd" or "ab" but not "abe"or "abg". For this case i don't think you can use LIKE. Try to use REGEXP. i think "ab[^g^e]?" should do the job for you.
SELECT name FROM table WHERE column REGEXP 'ab[^g^e]?';
I have a database with columns with the same name and a number after it, like:
med1, med2, med3, med4..... etc.
Is it posible to do something like this:
Select medewerker.med*
FROM table
Instead of this?:
Select medewerker.med1,
medewerker.med2,
medewerker.med3,
medewerker.med4
FROM table
Nope. you can use LIKE in a where clause but definitely not when specifying the columns to select
Use this instead if the only fields are the ones specified above.
SELECT *
FROM table
if not you cannot use a LIKE statement on column SELECT's.
if you are refering to values inside the medewerker column then use
SELECT *
FROM table
WHERE medewerker LIKE 'med%'
I have in table column pnum_s
I need get only that rows, which value in column pnum_s is exactly 10 symbol and all these symbols are only digits
what query must write for this?
I am trying
SELECT * FROM mytable WHERE pnum_s REGEXP '^\d+$'
But this not returns 0 rows
The pattern you are looking for is either '^[0-9]{10}$' or '^[[:digit:]]{10}$'.
Everything is in the manual.
I think with Mysql you'll want something like this:
^[[:digit:]]{10}$
Check out the reference page.
http://dev.mysql.com/doc/refman/5.1/en/regexp.html#operator_regexp
What you're looking for is this:
SELECT * FROM mytable WHERE pnum_s REGEXP '^[[:digit:]]{10}$';
try this pattern:
'^[0-9]{10}$'
I have a column that contains values like 5A898, 89KAS, 89ASD.
I'm trying to write a query that will only return rows where the third digit of the column is 'A'. For instance '89ASD' would be returned but '89KAS' would not. I'm not sure what the right way to go about this is. Regular expressions?
So...
SELECT column
FROM table
WHERE column = ?
WHERE column LIKE '__A%'
^^-- 2 underscores
should do the trick. two "whatever" characters, followed by an A, then followed by anything in any amount.
Maybe you can use MySQL's SUBSTRING
SELECT column
FROM table
WHERE SUBSTRING(column,3,1) = 'A'
where right(left(col,3),1) = 'A'
That can help... MarcB's answer is cleaner
You can do this with a regex, but I think it might be easier just coping with a string operation here:
SELECT column
FROM table
WHERE SUBSTRING(column,3,1) = 'A';