Display group data along with their last latest message [closed] - mysql

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 3 years ago.
Improve this question
I want to display result having data categorized in the group with their latest message according to date.
I tried grouping and having along with nested queries but no luck.
SELECT groupName,date FROM chat where groupName like '%he%' group by groupName,date having min(date);
I want the two rows to be printed along having the latest message with them.Here it would be row 4 and row 5. this is just an arbitrary data though which I need to impplement on bulk.

You don't need group by, just filtering:
select c.*
from chat c
where c.date = (select max(c2.date) from chat c2 where c2.groupname = c.groupname);

You can do it with NOT EXISTS:
SELECT c.*
FROM chat c
WHERE
groupName LIKE '%he%'
AND
NOT EXISTS (
SELECT 1 FROM chat
WHERE groupname = c.groupname AND date > c.date
)

Related

A way to retrieve some data from a table in MySql [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 2 years ago.
Improve this question
I want to retrieve some data in a table with certain criteria.
With the following criteria:
JurPengampu = 17
NRP codes must be different from one another, if the same, then the IdJurus = 17 is taken
The explanation is in the picture.
Thank you for help,,
enter image description here
Use analytical function as follows:
select * from
(select t.*,
row_number() over (partition by kodenrp order by idjurusan) as rn
from your_table t) t
where rn = 1
Or use NOT EXISTS as follows:
select t.*
from your_table t
where not exists
(select 1 from your_Table tt
where t.kodenrp = tt.kodenrp and tt.idjurusan < t.idjhurusan)

Updating a column with a Count of data from another column in the same table? [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 2 years ago.
Improve this question
As the title suggests, trying to take the count or possibly distinct count of a column, we call it year, to count the number of a years for an individual or populated ID and place it another column in the same table. Here is an idea of what I have so far and we want to update the table. Thank you.
Join group table to updated table directly:
UPDATE outputtable O JOIN
(SELECT personID, COUNT(DISTINCT year) AS countYear
FROM outputtable GROUP BY personID) temp ON O.personID=temp.personID
SET O.N=temp.countYear

MySQL: Show all data from one query and join data from another query where it matches [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 2 years ago.
Improve this question
Trying to understand SQL more as part of a POC I'm working on and have hit a snag. I have two select queries (shown below) and I want to combine these into a single query that:
Shows all of the results of query one
Joins the result of query two if the category column matches.
Provides a default of 0 if there is no match
Query one:
SELECT activityId, location, category, activityScore FROM activities WHERE location = "manchester";
Query two:
SELECT userId, category, userScore FROM userscore s WHERE userId = "32976428";
Expected Output:
The resulting query should show all activities in "manchester" along with the associated userScore if the specified use has one that matches that category. If there is no userscore then 0 should be returned instead.
Thanks for any help.
Carl
I think you need a LEFT JOIN on your userscore table
SELECT a.activityId, a.location, a.category, a.activityScore,
s.userId, ISNULL(s.userScore,0) as userScore
FROM activities a
LEFT JOIN userscore s ON s.category = a.category AND s.userId = "32976428"
WHERE a.location = "manchester";

Show in the tables, only the last statues [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 2 years ago.
Improve this question
I have a simple entry in the oracle, there are 3 columns, date, API name and status. I want that in the answer I had not all history, and only the last on each of Names of API (only 7). I will be grateful for your help. I know that asked of the very difficult but I'm just new to oracle.
select l.log_date,l.job_name,l.status from user_scheduler_job_log l
could be you want the related status for name and last log_date
select u.job_name, u.status, t.max_date
from user_scheduler_job_log u
INNER JOIN(
select MAX(l.log_date) max_date, l.job_name
from user_scheduler_job_log l
GROUP BY l.job_name
) t on t.max_date = u.log_date
AND t.job_name = u.job_name

Querying a 1 to many table where the many side has at least one row [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 7 years ago.
Improve this question
Have a common schema, with two tables.
users table contains the columns id, name.
checkins table contains the columns user_id, checkin_date.
in this hypothetical, users can have many instances of rows in the checkins table.
checkin_date in this case is of type date
I want to be able to query for all users who have at minimum 1 checkin in the checkins table where the checkin is after 2016.
I would suggest using exists:
select u.*
from users u
where exists (select 1
from checks c
where c.user_id = u.id and c.checkin_date >= '2016-01-01'
);