query to ignore first 2 rows - mysql

i have a query to fetch 100 rows of events ordered by timestamp. i want to ignore top 2 entries from the result set. The problem is that there is no criteria match (simply to ignore first 2 rows).
i am using pager (drupal) which results 10 events per page. If i process it after fetching 10 rows i lost 2 entries (first page contains only 8 entries). how to solve the problem ?

If you are using Views, you can just set the offset to 2 which will ignore the first two records.

USe limit
LIMIT 2,98

LIMIT 2,100
Add that to your SQL command, I think it should work.

You can't use offsets with pager_query() which I assume you're using here. Maybe you need to reconsider how you're querying? Maybe run a query for the first two records, and then in your pager SQL use a WHERE condition to exclude the IDs of the first two results.

Related

What order do Duplicates get Removed in Power Query?

When running Remove Duplicates in Power Query, does it leave the 1st instance alone and then delete any following duplicates? E.G. If there were duplicates on rows 10,11 and 12, it would delete rows 10 & 11? Is there documentation on this somewhere?
Thanks!
As far as I am aware, remove duplicates will remove items based on the order the data was initially loaded into Power Query. Any sorting or other operations you have performed after the data is loaded will not be factored into this. So duplicate items on rows 11 and 12 would be removed in your example, even if you sorted the data so the items on rows 11 and 12 were now above the item on row 10.
It is possible to make remove duplicates follow the current sort order if you use the function Table.Buffer() on the data before using the remove duplicates function in PQ (the actual function it runs is Table.Distinct(). This is because Table.Buffer() loads the table at the current state it is called into memory, and this resets the "load" order that is used to remove duplicates by Table.Distinct.
In practice the simplest way to do it looks like changing the default function when you use Remove Duplicates from this
= Table.Distinct(#"Sorted Rows", {"DuplicateColumn"})
to this
= Table.Distinct(Table.Buffer(#"Sorted Rows"), {"DuplicateColumn"})
Not sure about documentation but from experience: Yes, the first item is retained, any duplicates following will be removed.
With this knowledge under your belt you can use an Index columns to manipulate the order of entries if the default order does not produce the result you want.

ms access stops working when I open query having 20 million records with one sort

I have a query which combines different tables without any link so it create combination .Numbers of records has reached 20 Million , I have sorted these records by one field . MS Access hangs and stops working .Please anyone who can help in speeding up query or make it working.Thanks
Combining tables without telling the query how to relate one table to another is called a "cross join" as you say it creates a combination of the records.
It's easy to get very large results using a cross join, just 5000 rows in each of two tables in a cross join will generate 25 million records, just 300 records in each of three tables will give 27 million. With just 5000 or 300 records per table MSAccess will fly, but asking it to run a query to create ~20M records will take time, that's just how it is.
I suggest you tell us what you are trying to do, I expect that there should be a relationship between the tables, or at least something in the query to tell MSAccess which of the 20M records you want to see. I expect you don't want to scroll through 500000 or so pages of data to find what you are looking for.
One method would be to change your query to a create-table query using no filters.
Then create indexes in the new table on the fields you wish to filter on.
Now, use this table as source in a query where you apply the filters you wish.

Taking and filtering MYSQL results on another params table

Please help me with the query.
I want to get all projects_ids, that contain params and values of params.
When i use one criteria (not three, as an image) - it works and gaing results!
When use all, I think the CPU is trying to get a record when sometimes 3 criterion are passed. Need to get all projects_ids that contains criterion.
My solution at this time is SELF-JOIN.
For each param i create "JOIN" to table ON "projects_id", and add more WHERE statements with new tables.
10 params = 10 joins.

Different Number of Row counts?

I just created a table and ran a program which should add 170,256 rows.Then I checked the number of rows using PHP MyAdmin GUI. Below is the image.
According to the "Rows" column, I got only 162,230 rows! Then I ran the below query
SELECT COUNT(*) FROM `key_hash`
This generated the below result, which should be correct.
So my question is, how come the same thing display 2 different values? How should I know which is correct?
SELECT COUNT(*) FROM `key_hash`
provides you with exact row count.
What you see in summary (162,230) is just estimation (hence ~ sign)
Here is more detailed explaination
Why is the estimated rows count very different in phpmyadmin results?

Mysql sum as last row

Is it possible to have the SUM of all numaric fields in the last of a set of rows?
As of now, I'm using a very simple query such as:
SELECT
*,
SUM((UNIX_TIMESTAMP(end) - UNIX_TIMESTAMP(start))/3600)
FROM
times
in SQL you cant have a column that appears in only one row, likewise, you also cant have a row that doenst contain all the columns from the other rows.. So having a row that contains something unique is not possible. You can, however, add the calculated column to all rows in the dataset or do the calculation in the calling code after the data is returned.
I think what you are looking for is GROUP BY WITH ROLLUP you will find details on that in the MySQL manual.