I'd like to run a query for an artist's names. An artist could have a stage name, a full name (latin), korean name, nickname, etc.
I can't find how to seperate these names in a query URL.
https://commons.wikimedia.org/w/api.php?action=query&list=search&srnamespace=6&srlimit=500&format=json&srsearch=Taeyeon|Kim Tae-yeon|Taengoo|김태연
If I run the query for only 1 name, it brings the results, but got nothing with more names.
Use the keyword OR instead of |.
That means, run the following query:
https://commons.wikimedia.org/w/api.php?action=query&list=search&srnamespace=6&srlimit=500&format=json&srsearch=Taeyeon OR "Kim Tae-yeon" OR Taengoo OR 김태연
Related
I have a column in my SQL database (using mySQL) 'lastname', which has any number of employee's last names in it. I want to write a query that handles a search for last names using a comma delimited list.
So the user will type:
Garcia, Smith, Jones
And that gets stored in a String, lastNameQuery, which then gets passed into my backend API function that calls the SQL command. I want to return all employees in the DB that have those last names.
Is there any kind of SQL SELECT command I can use that search using a list like that? For my other functions (which only handle a single search term) I'm using this:
"SELECT * FROM employees WHERE salary LIKE '%${salary}%'"
Which works great. Is there some way I can modify it to handle a list? I can always break up the single String ("Garcia, Smith, Jones") into an array if necessary so that's not a problem. Any ideas?
You need to either do:
(lastname like '%Garcia%' or lastname like '%Smith%' or lastname like '%jones%')
or create a fulltext index on lastname (alter table employess add fulltext (lastname)) which would let you do
match (lastname) against ('Garcia, Smith, Jones')
but won't do things like find Garcia if you search for just "Garc".
I am using PHP to access a mysql database field that contains up to 2500 characters per record.
I want to build queries that will return only the records that include a single word, like 'taco'.
Sometimes, however, the user will need to search for a word like 'jalapeno'. Except that jalapeno may exist in the database as 'jalapeno' or as 'jalapeño'. The query should return both instances.
As a further complication, the user may also need to search for a word like 'creme', which may appear as 'creme' or 'créme', but never as 'crémé'.
It seems like I should be able to construct something that uses a replace, and then a Regular Expression, so that the letter 'n' is always replaced with '[n|ñ]', and then search for a string with an embedded Regular Expression like this: 'jalape[n|ñ]o'. Except that does not work. MySQL treats the RegEx syntax as literals.
None of the following return the results that I am looking for:
SELECT id, record FROM table WHERE record like '%jalapeno%';
SELECT id, record FROM table WHERE record REGEXP 'jalapeno';
SELECT id, record FROM table WHERE record REGEXP 'jalape[n|ñ]o';
SELECT id, record FROM table WHERE REGEXP_LIKE(record, 'jalape[n|ñ]o', 'im');
Additionally, I can use PHP to do a replacement of the potential characters, but I end up with stuff like this:
SELECT id, record FROM table WHERE (record like '%creme%' || record like '%crémé%');
I would be Ok with a search like this, but it seems overly complicated to construct programmatically:
SELECT id, record FROM table WHERE (record like '%creme%' || record like '%crémé%' || record like '%cremé%' || record like '%cremé%' );
Is there a MySQL method that provides a REGEX 'OR' to be embedded within a String?
Maybe something like this:
SELECT id, record FROM table WHERE record like '%cr[e|é]m[e|é]%' ;
Or is there another solution that would not require the construction of an excessively convoluted SQL Statement?
Thanks for anyone who spent time trying to figure this out.
As I commented above, REGEXP_LIKE() does not appear to be a valid MySQL function for the current release.
Here is my solution; Note that this works for MySQL 5.7.x.
SELECT id, record FROM table WHERE record RLIKE 'jalape(n|ñ)o';
I want to retrieve the last part of a large string in mysql after occurence of a particular substring. Please advice about how to do that.
For e.g. the main string contains
"New Delhi is capitalof India".
"Berlin is capitalof Germany".
I need to retrieve only India and Germany. I want know how to retrieve the data occuring after the specific substring like 'capitalof'.
I need to do this in mysql.
You can use substring_index
select
substring_index(title,'capitalof',-1)
from table1
DEMO
I have this select statement where I get all ids for a particular name:
select name from table1 where id=100;
var1=DBSession.query(table1).filter(table1.id==100).first().name
This returns me with just the first name value for the id 100. However, My query results multiple names and I have to use the all clause like this
varlist=DBSession.query(table1).filter(table1.id==100).all()
Then I am trying to access name from varlist like
for i in varlist:
otherlist.append(varlist.name)
because this query doesnt put all names in the list:
varlist=DBSession.query(table1).filter(table1.id==100).all().name
Can someone tell me how to get names from .all() directly into "varlist" without using an intermediate list?
The all() method is simply syntactic sugar for calling list on the query. So since you want a single column and not the entity, something like this should work,
names = [name for name, in DBSession.query(table1.name).filter(table1.id == 100)]
Slightly modifying #Jared's result to make this look better with .all():
namelist=[n.name for n in DBSession.query(table1).filter(table1.id==100).all()] also works. Thank you Jared.
I have the following stored proc :-
SELECT Id, Name
FROM FooBars
WHERE CONTAINS(Name, 'FORMSOF(Tesaurus, #query)')
Works fine when there is one word i the query: eg. foo*
But it fails when I want to have more than one word which i'm trying to look for.
eg. foo* bar* (this means any rows that have words that start with foo and start with bar).
What format does my #query argument need to look like, to enable multiple words for a Full Text Search with a Thesaurus?
As far as I know, if you want to search for two or more expressions, you need to concatenate those with either AND, OR or NEAR, something like this (straight from Books Online):
USE AdventureWorks;
GO
SELECT Name
FROM Production.Product
WHERE CONTAINS(Name, '"chain*" OR "full*"');
GO
SELECT Description
FROM Production.ProductDescription
WHERE CONTAINS(Description, 'bike NEAR performance');
GO
SELECT Description
FROM Production.ProductDescription
WHERE ProductDescriptionID <> 5 AND
CONTAINS(Description, ' Aluminum AND spindle');
If and how that would work together with your FORMSOF(...) expression is unclear to me - but I'm sure you could quickly try that, no?
SELECT Id, Name
FROM FooBars
WHERE CONTAINS(Name, 'FORMSOF(THESAURUS, "foo*")'
OR 'FORMSOF(THESAURUS, "bar*")')
Also make sure to spell "thesaurus" correctly in your FORMSOF () expression! :-)
Marc