I'm doing full text search using sqlite and below are some select query examples that I'm using.
Ex:
SELECT * FROM table WHERE table MATCH 'column:father* OR for*' ORDER BY rank;
SELECT * FROM table WHERE table MATCH 'column:exam* AND yo*' ORDER BY rank;
These queries are not working properly. Giving me all the rows in the database as the result. I cannot use AND/OR with the Match operator when using asterisk. Any solutions?
Thanks.
Related
I am using Google Sheets and have a connected query where I am using parameters. When one of the parameters is configured to be a subquery, the query will run, but no results are returned.
For example, here is my (simplified) query:
SELECT *
FROM table
WHERE campaign IN (#CAMPAIGN);
In this example, I have the #CAMPAIGN parameter in the Google Sheet configured as:
SELECT DISTINCT campaign FROM table2
If I manually substitute the parameter in the BQ console, it runs fine and returns the expected results. Is there a reason this functionality does not work with parameter substitution in the Google Sheet? Is there a way around this?
Depending on how much SQL SELECT type lookups you do, it may help to use a #customfunction that I wrote. You need to place my SQL .js in your Google sheets project and the =gsSQL() custom function will be available.
The one requirement for this versus using =QUERY() is that unique column titles are required for each column.
It is available on github:
gsSQL github project
This example works if each sheet is a table, so it would be entered something like
=gsSQL("SELECT books.id, books.title, books.author_id
FROM books
WHERE books.author_id IN (SELECT id from authors)
ORDER BY books.title")
In this example, I have a sheet named 'books' and another sheet named 'authors'.
If you need to specify a named range or an A1 notation range as a table, this can also be done with a little more work...
=gsSQL("SELECT books.id, books.title, books.author_id
FROM books
WHERE books.author_id IN (SELECT id from authors)
ORDER BY books.title", {{'books', 'books!$A$1:$I', 60};
{'authors', 'authors!$A$1:$J30', 60}}, true)
In this example, the books and authors come from specific ranges, the data will be cached for 60 seconds and column titles are output.
PRAGMA table_info(myTable)
This query selects all the info in a table, for example: if there are 2 columns in a table then this query will select all the column names, column types e.t.c
I just want add one clause i.e I want to get info of specific columns that I define in the query.
Like this:
PRAGMA table_info(myTable) where columnNames = 'a' and columnNames = 'b' // this is wrong query but I just mentioned it to make my question more clear.
How can I do this?
You can pragma_table_info() in a query with a WHERE clause:
SELECT *
FROM pragma_table_info('myTable') -- note the single quotes
WHERE name IN ('a', 'b') -- equivalent: name = 'a' OR name = 'b'
See the demo.
I'm trying to query data based on tag values. Is it possible to include multiple queries in the where clause . I could not find an operator similar to the IN operator in SQL.
select * from students where rollNumber='1' limit 10
students is the measurement and rollNumber is a tag. I want include multiple values of rollNumber in the query.
Any suggestions to solve the problem?
InfluxDB does not have IN operator, however it supports Go-lang regular expressions in WHERE clause for fields and tags. Regular expressions are enclosed with / and require adding ~ after comparison operator:
select * from students where rollNumber =~ /1|2|3/ limit 10
This will return 10 students, where rollNumber tag contains 1 or 2 or 3.
For a precise match the following should work:
select * from students where rollNumber =~ /^[1|2|3]$/ limit 10
Note: In case of filtering fields, if the type of fields is not string, regex will not work...
But as noted in the comments, using OR operator with explicit comparison should work better, as tag index can be used for more efficient querying.
This ActiveRecord query works in SQLite:
SlotReq.group(:team_id)
In PostgreSQL, the same query gives this error "GroupingError - column slot_reqs.id must appear in the GROUP BY clause or be used in an aggregate function"
Based on the answer to this question I changed my query to:
SlotReq.select("slot_reqs.team_id").group("slot_reqs.team_id")
and it works as expected.
I would like to know if I'm doing it right and why does this work?
Yes, you are doing it right, although you could also use:
SlotReq.select(:team_id).group(:team_id)
What happens is that PG (among other DB's) needs that all column names in SELECT must be either aggregated or used in GROUP BY clause; this is because, if any unagreggated column is omitted, it could lead to indeterminate behavior (i.e. What value should be used in that column?)
So, by specifying in select just the column you want to group, you don't omit any column; on the other hand, using group withoutselect, is equivalent to doing SELECT * FROM table GROUP BY column, which brings all columns but only one being specified on GROUP BY clause.
I have a sqlite database that I'm trying to build a query. The table column I need to retrieve is iEDLID from the table below :
Right now all I have to go on is a known iEventID from the table below :
And the the nClientLocationID from the table below.
So the requirements are I need to get current iEDLID to write, lookup from tblEventDateLocations for dEventDate and the tblLocation.nClientLocationID based on the tblLocations.iLocationID I already have and event selected on this screen.
So I would need a query that does a "SELECT DISTINCT table EventDateLocations.iEDLID FROM tblEventDateLocations ...."
So basically from another query I have the iEventID I need, and I have the event ID i need but where the dEventDate=(select date('now')) I need to retrieve the iEventDateID from table EventDates.iEventDateID to use on the table EventDateLocations
this is the point where I'm trying to wrap my head around the joins for this query and the syntax...
It seems like you want this:
select distinct edl.iEDLDID
from
tblEventDateLocations edl
join tblEventDates ed on edl.EventDateId = ed.EventDateId
where
ed.EventId = ?
and ed.dEventDate = date('now')
and edl.nClientLocationID = ?
where the ? of course represent the known event ID and location ID parameters.
Since nClientLocationId appears on table tblEventDateLocations you do not need to join table tblLocations unless you want to filter out results whose location ID does not appear in that table.