Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
I have a table "USER" in MySQL , some columns are "ID","Name","Birth" and "Death"... Birth and Death save date values.
I want to display both Birth and Death and then order by date ASC.
Here is an example from what I have and what I need..
column Birth:
1-2-99
2-2-99
column Death:
1-1-99
2-3-99
desired result from a query:
1-1-99 (from death col)
1-2-99 (from Birth col)
2-2-99 (from Birth col)
2-3-99 (from death col)
The example is displayed as (DD,MM,YY)
Use UNION or UNION ALL:
SELECT `date`
FROM
(
SELECT death AS `date` FROM tablename
UNION ALL
SELECT birth FROM tablename
) AS t
ORDER BY `date`;
Related
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 1 year ago.
Improve this question
I want to get lastupdate datetime order by updateTime but prevent for redundant date in my output
desired result
2021-06-25 15:46:57
2021-06-26 15:48:52
2021-06-27 17:11:52
2021-06-28 17:17:33
2021-06-29 15:16:29
I tried this
SELECT t.updateHistoryID, t.updateTime
FROM web_historyupdate t
INNER JOIN ( SELECT updateHistoryID, max(updateTime) as maxdate
FROM web_historyupdate
GROUP BY updateHistoryID ) tm
ON t.updateHistoryID =tm.updateHistoryID
AND t=tm.maxdate
You want the maximum datetime per date. As mentioned, "Maximum" translates to MAX in SQL and "per" transates to GROUP BY. One way to apply this to your data:
select *
from web_historyupdate
where updateTime in
(
select max(updateTime)
from web_historyupdate
group by date(updateTime)
)
order by updateTime;
There exist of course other ways to do this. You could for instance select every row for which NOT EXISTS a row on the same day at a later time.
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 the above table structure in the database and I want to calculate the upcoming abbreviation for an id (if a particular abbreviation has an actual date present (achieved) then it should give the current_date(which will be upcoming date even if it's in past) and next upcoming abbreviation for that particular id): if the last abbreviation has an actual date (for which category is also present).
expected result:
I'm new to SQL, i guess it can be achieved by taking maximum of actual_date present for abbreviation for a id.
If you want the abbreviation for each id with the maximum actual date, you can use row_number():
select t.*
from (select t.*,
row_number() over (partition by id order by actual_date desc) as seqnum
from t
where actual_date is not null
) t
where seqnum = 1;
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
I need to be able to find all employees whose review is due in the next 45 days. I have the MS SQL:
Select *
from Employee
where DATEDIFF(yy,HireDate,GetDate()+45) > DATEDIFF(yy,HireDate,GetDate())
How does this convert to MySQL?
try:
Select *
from Employee
where DATEDIFF(HireDate,DATE_ADD(CURDATE(), INTERVAL 45 DAY)) > DATEDIFF(HireDate,CURDATE())
I think you can just use CurDate instead of GetDate, so it'd just be:
Select * from Employee where DATEDIFF(HireDate,CurDate()) > DATEDIFF(HireDate,CurDate())
You should only need to check DATEDIFF once. Just get the number of days and compare.
SELECT *
FROM Employee
WHERE DATEDIFF(CURDATE(), HireDate) <= 45
Docs for MySQL's DATEDIFF (and other date/time functions): http://dev.mysql.com/doc/refman/5.1/en/date-and-time-functions.html
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
In my database in table_a every row has a date_created like "2011-04-17"
Now some of these dates are in the past, but my question is how can I retrieve the latest date that has not yet passed?
Try this one
SELECT * FROM table_a WHERE CURDATE() <= date_created
CURDATE()
Returns the current date as a value in 'YYYY-MM-DD' or YYYYMMDD
format, depending on whether the function is used in a string or
numeric context.
Can you try this,
SELECT * FROM table_a WHERE date_created >= CURDATE()
IF date_created is a date datatype then you can use
SELECT *
FROM table_a
WHERE date_created >= NOW()
LIMIT 1
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
I need to create a query in mysql to retrieve data where CREATED_DATE range should be 20th of current month to 20th of previous month. Please suggest..thanks
You can get dynamic records using current month, by the following query
SELECT * FROM table_name WHERE CREATED_DATE BETWEEN
DATE_FORMAT(NOW(),'%Y-%m-20') - INTERVAL 1 MONTH
AND DATE_FORMAT( NOW(),'%Y-%m-20')
Check the live result at the fiddle http://sqlfiddle.com/#!2/4668c/7
SELECT
*
FROM
your_table
WHERE
`CREATED_DATE` BETWEEN "2013-10-20" AND "2013-11-20";