Combine different properties into one colum in #ask query in semantic mediawiki - mediawiki

Is it possible to combine two properties with the same datatype into one column in an #ask query in SMW?
Suppose I have different datasets with Identifiers that are named differently:
#Object1
[[Has isbn::9780552145985]]
#Object2
[[Has id=83897239]]
I would like to combine these two in one column in an #ask query, like this:
{{#ask:
[[Category:Besitz]]
|?Has id = ID
|?Has ISBN = ID
|format=broadtable
}}
In the result I would like to have only the one column ID instead of two columns that are called
ID.
Thank you in advance!

Use template format instead of broadtable with template like
{{!}}-
{{!}} {{{Has isbn|{{{Has id|}}}}}}
Or install Semantic Scribunto, use mw.smw.ask and row['Has id'] or row['Has isbn'].

Related

Do you know how to include and exclude parts of a string in mysql where clause?

I am having trouble using and/or/not operators in my where clause to create the following logic.
I have a field called package that lists out many different names of packages and I need to include/exclude specifically based on the following rules:
If a package includes renew, optout, or discount in the name AND ALSO does not include premium in the name, those names need to be excluded from the dataset. (so If a package has renew, optout, or discount in the name and the word premium, these are included in the dataset)
Furthermore, Anything with employee or Comp needs to be excluded.
Anything else not listed in the rules above would be included in the dataset.
Any help would be greatly appreciated and added to my sql tool belt!
Sounds like something like:
SELECT *
FROM packages
WHERE name NOT LIKE '%employee%'
AND name NOT LIKE '%Comp%'
AND (name NOT LIKE '%renew%' OR name NOT LIKE '%optout%' OR name NOT LIKE '%discount%') OR name LIKE '%premium%')
There are 2 conditions that exclude rows, so what you need is a WHERE clause containing boolean expressions starting with the NOT operator combined with AND:
where
not ((package like '%renew%' or package like '%optout%' or package like '%discount%') and (package not like '%premium%'))
and
not (package like '%employee%' or package like '%comp%')

FIND_IN_SET() not working for single value

I have table named post in which there is a column called visible_user_ids in which comma separated values are there. When I display the post by respective user then I used the FIND_IN_SET().
e.g. FIND_IN_SET('8','visible_user_ids') it shows the all the records from post table for user id 8 when visible_user_ids column contains comma separated user ids such as
3,5,8
8,5
8,1,12
etc.
but when visible_user_ids column contain only one value i.e. 8 then it does not display the post table record.
Please suggest a solution. Whether FIND_IN_SET() works for single value?
Instead of
FIND_IN_SET('8','visible_user_ids')
Try this
FIND_IN_SET('8',visible_user_ids)

Using LIKE in sql query

In a query in which I am looking for results based on the title of articles, I use the LIKE part as followed:
WHERE title LIKE %searchquery%
In my database one title is like this:
Economy in America
My problem:
With my current query, this title does NOT get listed, when the user enters the following searchquery:
america economy
When the user enters only one of these terms, everything works fine and the title gets listed.
How come?
How do I need to adjust my query so that my sql query will also work when the user enters more than one term?
The MySQL LIKE operator is limited in that it doesn't offer full regex support of the sort for which you are really looking. That being said, one option you could try would be to split your search query terms and then join multiple LIKE conditions using AND. Consider this example:
WHERE title LIKE %queryterm1% AND LIKE %queryterm2%
If queryterm1 be 'america' and queryterm2 be 'economy', then this would match the title 'Economy in America'.
You will need to split the query by whitespaces and then add multiple LIKE statements like this:
WHERE title LIKE '%america%' AND title LIKE '%economy%'
As #Tim says, you must write some routine in your application to divide the string terms and inject them in the select where clause. Or you may need to write some stored procedure for that.

can i pass more than one parameter within SOUNDEX() function to get multiple value result

My student table stu_table contains many different student name but most of them sound similar, in the field stu_name.
For example:
Mrinmoy, Minmay, Mrinmay, Minmoy,
Tanmoy ,Tanmay, Tonmoy, Tanmy,
Rajesh, Rajes,
Anirban, Anirbon.
Here first 5 make a similar sound group of name
Next 3 make a similar sound group of name
and last 2 make another group of similar sound name.
Can i pass more than one parameter (for example Mrinmoy and Tanmoy) within a single SOUNDEX() function to fetch both result.
If yes then how to pass it. Please help.
soundex() accept only one parameter.
So you have to use OR in sql.
You can try this sql.
SELECT * FROM `stu_table` where soundex(`stu_name`)= soundex('Anirban') OR soundex(`stu_name`)=soundex('Tonmoy')

concatenate using Allen Browne's example

I am using the 'concatenate related' module created by Allen Browne to concatenate rows into a single field. At first I had a lookup field at the table level and later realized this is not a good approach. So I deleted the lookup column and instead made a query for selecting values from the lookup table on my form and then store that value as a number in the table.
The module works when I concatenate the values but it is listing the number (id) whereas I would like the actual description (i.e. 1 = Red, 2 = Blue, etc.)
My SQL query code is as follows:
SELECT DISTINCT
tblCompany.JobID,
concatrelated("type","tblMonitor","JobID = " & [jobID]) AS Expr1
FROM tblCompany;
I would like "type" to display the description instead of the number. I know if I store my lookup value as text instead of number it will work. But for efficiency it seems the number should be stored in the table and then query for the description when you need it....or maybe text is fine??? I'm guessing I would need to add the lookup table to this query. I have tried but with no luck so far.
Create a query which joins tblMonitor with the table which holds the type description field. Then use that query with ConcatRelated.
ConcatRelated("type_descriptn","YourQuery","JobID = " & [jobID])