reproduce select distinct with get_db_data - wikimedia

I am using for the first time MediaWiki so I apologize if this is a trivial question.
I am retrieving data from an external database using
{{#get_db_data:
db=mydb
|from=tabledata
|data=ts=ts,obs=observer,des=description
}}
How can I obtain with this parser the same effect of the sql command SELECT DISTINCT ?
Thank you.

I found out that this is possible by adding DISTINCT as follows
{{#get_db_data:
db=mydb
|from=tabledata
|data= des = DISTINCT description
}}

Related

Execute SQL Simple Query

I have a simple query that I'm sure anyone whos not a novice will be able to easily solve, I have a table which has a bunch of 'tags' for instagram. I am trying to extract TAGS where DATE = today.
A rough copy of what I want is shown below, I know the syntax is incorrect which is why I'm struggling, but I think you can see what I'm trying to achieve, any advice welcome :)
ExecuteSQL
(
SELECT IGs::tag
FROM IGs::
WHERE IGs::creation date = 22/10/2048
;)
However I would prefer that creation date = $$todaysdate ( I will set the variable before the ExecuteSQL in the script.
You need to use quotes around the query. Something like this.
ExecuteSQL
(
"SELECT tag
FROM IGs
WHERE \"creation date\" = ?"
;"";"";$$todaysdate
)

Hive Strange code syntax test.`(submit_date)?+.+

I have a HQL(Hive Query) file which has code like
select * ,'(submit_date)?+.+' from test
Table test has several other filed after submit date all of which are returned in the output of this query, but i couldn't understand how this thing works. ?
does any1 have any idea, i couldn't find any Doc related to this syntax
This is documented as the REGEX column specification:
A SELECT statement can take regex-based column specification.
We use java regex syntax. Try http://www.fileformat.info/tool/regex.htm for testing purposes.
The following query select all columns except ds and hr.
SELECT `(ds|hr)?+.+` FROM sales

sql or trick to search through whole database

is there a way to actually query the database in a such a way to search for a particular value in every table across the whole database ?
Something like a file search in Eclipse, it searches accross the whole worspace and project ?
Sorry about that .. its MS SQL 2005
SQL Workbench/J has a built in tool and command to do that.
It's JDBC based and should also work with SQL Server.
You will need to use the LIKE operator, and search through each field separately. i.e.
SELECT * FROM <table name>
WHERE (<field name1> LIKE '%<search value>%') OR
(<field name2> LIKE '%<search value>%') OR
... etc.
This isn't a quick way though.
I think the best way would be to
1) programatically generate the query and run it
2) use a GUI tool for the SQL server you are using which provides this functionality.
In mysql you can use union operator like
(SELECT * from table A where name = 'abc') UNION (SELECT * from
table B where middlename = 'pqr')
and so on
use full text search for efficency
http://dev.mysql.com/doc/refman/5.0/en/fulltext-search.html
Well, your best bet is to write a procedure to do this. But to give you some pointers you can use the INFORMATION_SCHEMA.Tables to get a list of all the tables in a given database and INFORMATION_SCHEMA.Columns to get a list of all columns. These tables also give you the datatype of columns. So you will need a few loops on these tables to do the magic.
It should be mentioned most RDBMSs nowadays support these schemas.
In phpmyadmin, go to your database, reach the search tab.
Here you will be able to select all of your tables and search through your entire db in one time.

SQL Query in Hibernate

I'm carrying out a SQL query which looks like:
SELECT thi.*
FROM track_history_items thi
JOIN artists art
ON thi.artist_id = art.id
WHERE thi.type = TrackBroadcast
Group By art.name
ORDER thi.created_at DESC
This works fine when I run it directly on my database from MySql Workbench, but when I run in through Hibernate, I get a No Dialect mapping for JDBC type: -1 error.
Anyone have any ideas what could be causing it?
Probably one or more of the columns in the query is not supported by the mysql dialect... try expanding the * and add one column at a time until you find the offending one.
Then it is just a matter of deciding whether you need that column or not.

Hibernate distinct clause problem

I searched a lot around but cannot find the answer:
I have the following SQL query:
select distinct l.id_book from wa2011.tb_lending as l where l.id_user = 1
It's a very simple query but I cannot manage to write it. How can I write this in HQL?
Thanks a lot!
Cheers.
I tested the code with Hibernate 3.3.2 and MS SQL Server and it works fine:
select distinct u.id from User u where u.login='admin'
So I think your HQL code should looks almost the same (just rewrite it from SQL to object model mapped to Hibernate).