How to specify and offset for select query on a table? - pact

Is it possible to specify an offset for select query on a table ?

It's not currently supported. Some alternatives are below. But they depend on the use-case
Adding an index field to tables and querying on that range
Using something like timestamps to filter results
Indexing all the results in your own SQL table

Related

DynamoDB query 1 field greate than

I have games table.
To keep it simple, I will add only two fields for the question.
gameId:
deadlineToPlay:
I want to query for all games with deadlineToPlay > than today.
How would I set up the index for this? I thought I could create an index with just deadlineToPlay, but if I understand correctly when querying on hashkey, it has to be exact value. Can't use >.
I would also not like to use a scan, due to costs.
A way to workaround this would be to create or use an existing field which will have constant value (for example, field hasDeadline with value true).
Now you can create the table key like this: hasDeadline as HASH key and deadlineToPlay as SORT key (if the table is already created, you can define this key in a new GSI).
This way you will be able to query by hasDeadline = true and deadlineToPlay > today.

Use "where in" for LiteDB

I enjoy working with LiteDB in Xamarin.Forms. What is the best practice for getting list of objects from a table using list of ids or indexes in condition?
Currently, it looks for me like this:
_db.GetCollection<T>().FindAll().Where(q => listValues.Contains(Convert.ToInt32(q.GetProperty(idColumnName))));
listValues - list of searched ids.
idColumnName - column with indexes.
But FindAll retrives all records from LiteDB. Is there any more efficint options without full scanning?
Use the query in the Find method instead which will only retrieve entries based on your query rather than the full data set. This, according to the LiteDB's guidance, is more efficient than Linq queries on the full data returned: https://github.com/mbdavid/LiteDB/wiki/Queries
So your query would look like as follows
_d.GetCollection<T>().Find(q => listValues.Contains(Convert.ToInt32(q.GetProperty(idColumnName))))
I think you can just use collection.Query().Where("Column", 1,2,3) for this

New to sqlite and database work, how do I do this query?

I have a project I am working on and I am wanting to create a query that involves two tables from my database as pictured below.
What I want from the query is if DMN_LIST_COLS on the DOMAIN data table equals 1 I want to retrieve all the values from DMV_VALUE_1 of the DOMAIN_VALUE data table. What is the correct format for this query?
I know the query below is incorrect but how do I change this?
SELECT DMV_VALUE_1 FROM DOMAIN_VALUE WHERE DMN_LIST_COLS='1' FROM DOMAIN
Give this a try:
SELECT DOMAIN_VALUE.DMV_VALUE_1
FROM DOMAIN_VALUE INNER JOIN DOMAIN ON DOMAIN_VALUE.DMV_ID = DOMAIN.DMN_ID
WHERE DOMAIN.DMN_LIST_COLS ='1';
If DOMAIN.DMN_LIST_COLS contains actual numbers instead of text, you will want to remove the single quotes surrounding the 1 in the WHERE statement.

I have to update one table field as another field of different table in sql

I have to update one table field as another field of different table in sql. There are two tables, create_account and Trans_Details. I have to update amount field of create_account table and set it into current_balance of Trans_Details table. How can I join these two tables? please write a query for this.
You can utilize the sub queries to do this...
Example:
I do not know what kind of data base r u using i am just giving a pseudo code..
UPDATE create_account SET (amount) = ( SELECT current_balance FROM Trans_Details
WHERE filter = some_value) WHERE filter = some_value.
I have added the where clause in the query, please ignore if u want to update the entire row in the column amount.

Complex datasource issue in Dynamics AX

I have a grid that displays lines from a table. Now, I have these two requirements:
Show only the lines that contains values in the "hour" fields. The "hour" field is an array type.
Show the lines from a project and its subproject
My problem is this: to meet requirement #1, I need to use a select statement in my datasource since I cannot access array value using QueryBuildDataSource (this is a known limitation in Dynamics AX).
But to meet requirements #2 I need to have two "exists join", and this is not possible in Dynamics AX. For example the following code would not work:
select from table where
exists join tableChild where projectId = MyProjectId OR
exists join tableChild where parentProjectId = MyProjectId
How would someone address this issue?
From the select statement example you provided, it appears it may not be necessary to have two exist joins. A single exists join with the "OR" for the two possible conditions in its where clauses may be sufficient, of course, you should still have some relationship between table and tableChild for the join to make logical sense.
select from table
exists join tableChild
where (tableChild.projectId = MyProjectId || tableChild.parentProjectId = MyProjectId)
You can use array values in query ranges providing field IDs using fieldID2Ext function.
You can build view and apply confitions on top of it.

Resources