sql-like

SQL: Is it possible to 'group by' according to 'like' function's results?

☆樱花仙子☆ 提交于 2019-12-04 03:14:28
I am using Oracle SQL and I want to group some different rows that 'like' function results. To elaborate with an example: Let's assume I have a table MESA with one of the columns is a huge string. And I am counting the number of rows matching particular patterns: SELECT m.str, count(*) FROM MESA m WHERE m.str LIKE '%FRUIT%' AND (m.str LIKE '%APPLE%' OR m.str LIKE '%ORANGE%') So let's assume the result of this query is: FRUIT..afsafafasfa...RED_APPLE 20 FRUIT..afsafafasfa...YELLOW_APPLE 12 FRUIT..afsafafasfa...GREEN_APPLE 3 FRUIT..afsafafasfa...PURPLE_ORANGE 4 FRUIT..afsafafasfa...RED_ORANGE 45

Oracle query using 'like' on indexed number column, poor performance

落花浮王杯 提交于 2019-12-04 03:08:46
On Query 1 a full table scan is being performed even though the id is an indexed column. Query 2 achieves the same result but much faster. If Query 1 is run returning an indexed column then it returns quickly but if non-indexed columns are returned or the entire row is then the query takes longer. In Query 3 it runs fast but the column 'code' is a VARCHAR2(10) in stead of a NUMBER(12) and is indexed the same way as 'id'. Why does Query 1 not pick up that it should use the index? Is there something that should be changed to allow indexed number columns to perform quicker? [Query 1] select a1.*

how to make a like search in postgresql and node js

旧巷老猫 提交于 2019-12-04 03:08:02
问题 I am using node js and the module pg for connect to postrgresql i want to make a search for a database of tags but i can't make it work, in the variable tag i saved the param of the url , but the consult doesn't return any results. how can i fix? app.get("/tags", function(req, res){ var tag = req.query.q; res.json(tag) var search = db.client.query("SELECT * FROM tags WHERE name LIKE '%$1%'", [tag], function(err, result){ res.json(result); } ); }); 回答1: I don't know the node.js PostgreSQL

Possible bug in VB.NET 'Like' operator?

≡放荡痞女 提交于 2019-12-04 03:05:27
Why is it that the following evaluates as True ? Dim result = "b" Like "*a*b" Thanks. EDIT: To generalize this a bit, the following returns True : "String1" Like "*AnyText1*AnyText2*AnyText???******????*String1" VBA works correctly, returning False . PowerShell works correctly, returning False : PS C:\Users\XXX> "b" -Like "*a*b" False EDIT2: The link to the bug report: https://connect.microsoft.com/VisualStudio/feedback/details/748415/a-bug-in-net-like-operator I decided, for fun, to open up ilspy to debug this :-) in this method; private static void MatchAsterisk(string Source, int

SQL query to match one of multiple strings

牧云@^-^@ 提交于 2019-12-04 02:58:05
I have following data in table: +----------------------+----------------------------------------------------------+--------------+ | subscriber_fields_id | name | field_type | +----------------------+----------------------------------------------------------+--------------+ | 143 | Peshawar/Islamabad/Lahore/Swat/Mardan/Karachi | Job Location | | 146 | Karachi | Job Location | | 147 | Lahore and Karachi | Job Location | | 149 | Karachi, Mirpur Khas, Sukkur, Layyah, Gilgit, Charsaddah | Job Location | | 152 | Islamabad or Lahore | Job Location | | 155 | Islamabad | Job Location | | 157 | 7

How can you find a literal percent sign (%) in PostgreSQL using a LIKE query?

六眼飞鱼酱① 提交于 2019-12-04 00:33:51
I have character varying entries in a table where some (not all) values contain percentages, e.g., '12%' , '97%' , etc. I want to find all the values that contain percentages. In other words, I want to find all values that end with a percent sign ( '%' ). You can try like this: SELECT * FROM my_table WHERE my_column LIKE '%\%%' ESCAPE '\'; Format <like predicate> ::= <match value> [ NOT ] LIKE <pattern> [ ESCAPE <escape character> ] <match value> ::= <character value expression> <pattern> ::= <character value expression> <escape character> ::= <character value expression> You have to escape

MYSQL use 'LIKE' in 'WHERE' clause to search in subquery

筅森魡賤 提交于 2019-12-03 23:16:19
How would you use 'LIKE' to search in a subquery? E.g. i've tried doing this, but doesn't work: SELECT * FROM mytable WHERE name LIKE '% (SELECT name FROM myothertable) %' I have this so far: SELECT * FROM t1 WHERE t1.name IN (SELECT t2.name FROM t2) AND (t1.title IN (SELECT t2.title FROM t2) OR t1.surname IN (SELECT t2.surname FROM t2)) It's working ok as it returns exact matchs, but it doesn't seem to return my other records that are similar, so I would like to also check that: t1.title LIKE '%t2.title%' AND t1.surname LIKE '%t2.surname%' How would i do this? Using a JOIN: SELECT a.* FROM

How can LIKE '%…' seek on an index?

巧了我就是萌 提交于 2019-12-03 13:47:02
I would expect these two SELECT s to have the same execution plan and performance. Since there is a leading wildcard on the LIKE , I expect an index scan. When I run this and look at the plans, the first SELECT behaves as expected (with a scan). But the second SELECT plan shows an index seek, and runs 20 times faster. Code: -- Uses index scan, as expected: SELECT 1 FROM AccountAction WHERE AccountNumber LIKE '%441025586401' -- Uses index seek somehow, and runs much faster: declare @empty VARCHAR(30) = '' SELECT 1 FROM AccountAction WHERE AccountNumber LIKE '%441025586401' + @empty Question:

How to search millions of record in SQL table faster?

99封情书 提交于 2019-12-03 11:55:50
问题 I have SQL table with millions of domain name. But now when I search for let's say SELECT * FROM tblDomainResults WHERE domainName LIKE '%lifeis%' It takes more than 10 minutes to get the results. I tried indexing but that didn't help. What is the best way to store this millions of record and easily access these information in short period of time? There are about 50 million records and 5 column so far. 回答1: Most likely, you tried a traditional index which cannot be used to optimize LIKE

LINQ to SQL - select where text like string array

好久不见. 提交于 2019-12-03 09:56:06
问题 I have a List <string > of variable count, and I want to query (via LINQ) a table to find any items that contain any of those strings in the Text column. Tried this (doesn't work): items = from dbt in database.Items where (stringList.FindAll(s => dbt.Text.Contains(s)).Count > 0) select dbt; Query would be something like: select * from items where text like '%string1%' or text like '%string2%' Is this possible? 回答1: Check this article out to do what you want: http://www.albahari.com/nutshell