Home SQL Postgres find word first to appear among list of words in string field
Reply: 0

SQL Postgres find word first to appear among list of words in string field

user1540
1#
user1540 Published in May 20, 2018, 11:38 am

I have a simple query. Looking for a word in string field like the following:

Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/56.0.2924.90 Safari/537.36 2345Explorer/9.2.1.17116

I EXPECT "CHROME" ROWS ONLY AS AN OUTPUT

Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Safari/56.0.2924.90 Chrome/537.36 2345Explorer/9.2.1.17116

I EXPECT "SAFARI" ROWS ONLY AS AN OUTPUT

Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Explorer/56.0.2924.90 Safari/537.36 2345Chrome/9.2.1.17116

I EXPECT "EXPLORER" ROWS ONLY AS AN OUTPUT

Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Explorer/56.0.2924.90 Safari/537.36 2345Chrome/9.2.1.17116

I do not want "CHROME" rows as an output when I query for rows with "CHROME"

Think about Chrome only and chrome = 1 Then if I have 1-2-3, I want to output If 2-1-3 i don't want to output If 2-3-1 don't want to output

I want it only when it comes first.

I want to be able to display only field where Chrome appear first, then with another query only field where Safari is first (not this case). DO you have an idea please? beginning with the following code

 SELECT *
 FROM user_logins
 WHERE user_agent NOT LIKE '%iPhone%'
 AND user_agent NOT LIKE '%Linux; Android%'
 order BY id DESC
 LIMIT 1000
You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.314954 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO