| |

VerySource

 Forgot password?
 Register
Search
View: 926|Reply: 7

A simple SELECT problem

[Copy link]

1

Threads

3

Posts

4.00

Credits

Newbie

Rank: 1

Credits
4.00

 China

Post time: 2020-2-17 16:30:01
| Show all posts |Read mode
SELECT *
FROM t1
WHERE
(Col004 like '% keyword 1%') OR
(Col004 like '% keyword 2%') OR
 and
(Col003 like 'Keyword 3%') OR
(Col003 like'Keyword 4 ') OR
      
I want to find the record in T1 where Col004 contains keyword 1 or keyword 2 and Col003 contains keyword 3 or keyword 4. For example, a record Col004 containing the keyword 1 and Col003 containing the keyword 4 are eligible, but the above statement does not seem to be implemented? ? How to write the correct one?
Reply

Use magic Report

0

Threads

126

Posts

73.00

Credits

Newbie

Rank: 1

Credits
73.00

 China

Post time: 2020-4-20 15:15:01
| Show all posts
SELECT *
FROM t1
WHERE
((Col004 like '% keyword 1%') OR
(Col004 like '% Keyword 2%'))
 and
((Col003 like 'Keyword 3%') OR
(Col003 like 'Keyword 4'))
Reply

Use magic Report

0

Threads

126

Posts

73.00

Credits

Newbie

Rank: 1

Credits
73.00

 China

Post time: 2020-4-20 16:00:01
| Show all posts
SELECT *
FROM t1
WHERE
((Col004 like '% keyword 1%') OR
(Col004 like '% Keyword 2%'))
 and
((Col003 like 'Keyword 3%') OR
(Col003 like 'Keyword 4%'))

% Is missing
Reply

Use magic Report

1

Threads

3

Posts

4.00

Credits

Newbie

Rank: 1

Credits
4.00

 China

 Author| Post time: 2020-4-20 22:15:01
| Show all posts
It ’s not this% problem, I missed it here, I think it ’s the problem of the statement itself? ?
Reply

Use magic Report

1

Threads

3

Posts

4.00

Credits

Newbie

Rank: 1

Credits
4.00

 China

 Author| Post time: 2020-4-21 01:00:02
| Show all posts
The problem with this sentence:
(Col004 like '% Keyword 2%'))
 and
((Col003 like 'Keyword 3%')
and is reflected between these two, the other has no effect of AND
Reply

Use magic Report

1

Threads

2

Posts

3.00

Credits

Newbie

Rank: 1

Credits
3.00

 China

Post time: 2020-4-21 15:15:01
| Show all posts
First put SELECT *
FROM t1
WHERE
(Col004 like '% keyword 1%') OR
(Col004 like '% keyword 2%') OR made into a view, and then through SELECT *
FROM view WHERE (Col003 like 'Keyword 3%') OR
(Col003 like 'Keyword 4')
Reply

Use magic Report

0

Threads

17

Posts

12.00

Credits

Newbie

Rank: 1

Credits
12.00

 China

Post time: 2020-4-21 20:15:01
| Show all posts
SELECT *
FROM t1
WHERE
(
(Col004 like '% keyword 1%') OR
(Col004 like '% Keyword 2%') OR
)
and
(
(Col003 like 'Keyword 3%') OR
(Col003 like 'Keyword 4') OR
)
Reply

Use magic Report

0

Threads

211

Posts

108.00

Credits

Newbie

Rank: 1

Credits
108.00

 China

Post time: 2020-4-22 21:45:01
| Show all posts
--try

SELECT *
FROM t1
WHERE
((Col004 like '% Keyword 1%') OR (Col004 like '% Keyword 2%'))
and
((Col003 like 'Keyword 3%') OR (Col003 like '% Keyword 4%'))
Reply

Use magic Report

You have to log in before you can reply Login | Register

Points Rules

Contact us|Archive|Mobile|CopyRight © 2008-2023|verysource.com ( 京ICP备17048824号-1 )

Quick Reply To Top Return to the list