0

I have a table movies and nationality field, but it written diferently even if is the same information

example:
Británica Estadounidense
estadounidense Británica 
Británica y estadounidense

My query is that I have to get all the movies that are británica and estadounidense

My code:

SELECT query_name, nationality 
FROM directors 
WHERE nationality LIKE  '%ritánica%' || '%' || '%st%'

I don't know how to get when the 2 words are switched estadounidense Británica

2 Answers 2

1

I would use regex here to match entire words, regardless of case:

SELECT query_name, nationality
FROM directors 
WHERE nationality ~* '\yBritánica\y' AND nationality ~* '\yEstadounidense\y';
Sign up to request clarification or add additional context in comments.

2 Comments

is not matching the estadounidense británica
@foxDev Your data is the problem and both Gordon's and my answer should be working for you.
1

One method is two likes:

SELECT query_name, nationality 
FROM directors 
WHERE nationality LIKE '%ritánica%' AND
      nationality LIKE '%st%'

This would, of course, also work for the full names as well.

2 Comments

is not matching the estadounidense británica @GordonLinoff
@foxDev . . . It certainly should be. I see both subqueries in that string.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.