This would be my query:
SELECT * FROM Bans ORDER BY Date DESC LIMIT 10
Here's how the timestamp(Date) looks: September 01, 2012 - 10:33:13 | May 31, 2012 - 19:28:25, etc.. Now, my problem is, is that I have records from June, but they aren't showing.
How can I fix this?
Edit: This table should show the "Latest" 10 bans.
I may supose that dates are sorted in the alphabetical order, maybe you should try
SELECT * FROM Bans ORDER BY TO_SECONDS(Date) DESC LIMIT 10
Date might be considered as a keyword in MySQL. Wrap it inside the backticks. Dates are not in the correct form. Use TO_SECONDS and alter the query this way:
SELECT * FROM `Bans` ORDER BY TO_SECONDS(`Date`) DESC LIMIT 10
Related
Is there a way to use limit offset and get the most recent (MAX) date from that group
My table: column_id, column_data, column_date
I've tried
SELECT max(column_date) FROM table_name limit 2000 offset 22000
I'm trying to get the most recent date in the 2000 rows returned using the offset. In other words, I'm looking for the last date modified in each group of 2000.
The table structure above has 100,000 rows. each query gets 2000 rows and I would like to retrieve the most recent date from the 2000 rows (using offset).
You must extract the whole group then find MAX() over it:
SELECT MAX(date_column)
FROM ( SELECT date_column
FROM source_table
ORDER BY some_expression /* compulsory! must provide rows uniqueness! */
LIMIT #rows_in_group OFFSET #group_offset ) AS subquery
I tried researching this problem but I couldn't find anything that fits.
I have a query that pulls data the way I want, but it shows me results for the last 30 days only, the archive is about 3 years and I would like to add a parameter that will tell me the exact date, for example August 2019.
My query:
SELECT FROM_UNIXTIME(datetimeOrigination),
callingPartyNumber,originalcalledPartyNumber,
from_unixtime(datetimeDisconnect)
FROM corn.originalcdr
WHERE callingPartyNumber like '9000'
ORDER BY datetimeorigination DESC;
Could you please advise me on the best approach?
If you want to restrict, e.g., the origination datetime field to August of 2019, then add an appropriate criteria to the WHERE clause:
SELECT *
FROM corn.originalcdr
WHERE
callingPartyNumber = '9000' AND
FROM_UNIXTIME(datetimeOrigination) >= '2019-08-01' AND
FROM_UNIXTIME(datetimeOrigination) < '2019-09-01'
ORDER BY
datetimeOrigination DESC;
I have a table called 'Articles' in that table I have 2 columns that will be essential in creating the query I want to create. The first column is the dateStamp column which is a datetime type column. The second column is the Counter column which is an int(255) column. The Counter column technically holds the views for that particular field.
I am trying to create a query that will generate the last 30 days of records. It will then order the records based on most viewed. This query will only pick up 10 records. The current query I have is this:
SELECT *
FROM Articles
WHERE DATEDIFF(day, dateStamp, getdate()) BETWEEN 0 and 30
LIMIT 10
) TOP10
ORDER BY Counter DESC
This query is not displaying any records, but I don't understand what I am doing wrong. Any suggestions?
The MySQL version of the query would look like this:
SELECT a.*
FROM Articles a
WHERE a.dateStamp >= CURDATE() - interval 30 day
ORDER BY a.counter DESC
LIMIT 10;
Your query is generating an error. You should look at that error before fixing the query.
The query would look different in SQL Server.
When i get rows from the db with the same exact same date's but the id's get fillped as such:
select * from rent ORDER BY date_at ASC;
id: 70 date: 12-01-2013
id: 69 date: 12-01-2013
Is there a way to work around this so that i can sort by date but still retain the id order if the date's are the same?
Add another column you want to sort by in the order condition
SELECT * FROM rent
ORDER BY date_at ASC,
id ASC
The following code works, but I want the groups to show their latest query by datetime not the first datetime query. I've tried changing around the ORDER BY from ASC/DESC, but that just changes the order of all the groups, not the data within the groups. I need for both all the inside data of the groups and all the groups to order by the latest datetime.
$query="SELECT * FROM emails
WHERE sentto='$sid'
GROUP BY sentto
ORDER BY datetime DESC LIMIT $eu, $limit ";
Instead of it showing groups and ordering them by the first query:
Message from Sam Richards on January 22, 2011 (this is a group)
Message from John Smith on January 5, 2011 (this is a group)
I want it to show groups and order them by the latest query:
Message from John Smith on April 19, 2011 (this is a group)
Message from Sam Richards on March 10, 2011 (this is a group)
Please help.
I think part of your problem is that you are selecting non-aggregate columns with a group-by query. You should be explicit about which values you want it to return in the aggregate query result.
SELECT sentto, MAX(datetime) AS datetime FROM emails
GROUP BY sentto
ORDER BY datetime desc LIMIT $eu, $limit;
I'm still not sure that this gives you what you want. It sounds like you want to actually retrieve the rows for each individual email and just use the GROUP BY maximum for sorting. To do that, you'd probably need to do the above query, then go back and do a second query for each sentto. I can't think of a way offhand to do it in a single query.
SELECT * FROM emails
WHERE sentto=$sid
ORDER BY datetime DESC;
(For each sentto returned in the first query.)
How about:
ORDER BY sentto ASC, datetime DESC
To sort the data with in the groups you need to include sentto in the ORDER BY clause.
Try this:
SELECT * FROM emails
WHERE sentto='$sid'
GROUP BY sentto
ORDER BY sentto, datetime DESC LIMIT $eu, $limit