Get current month birthday list form employee table [closed] - mysql

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Closed 8 years ago.
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
Questions concerning problems with code you've written must describe the specific problem — and include valid code to reproduce it — in the question itself. See SSCCE.org for guidance.
Improve this question
I have an employee table with dob. Every month i want the list of current month birthday list.
I want the query for the current month employee birthday list. The dob file date like this '31-01-1986' and so on. Please help me to get this.

Since your dob column contains values like '31-01-1986', it must be a string datatype rather than a temporal one. This makes it difficult (and slow) to perform date operations such as you desire; you may be better off doing a pure string manipulation instead:
SELECT *
FROM employee
WHERE CAST(SUBSTRING(dob, 4, 2) AS UNSIGNED) = MONTH(CURRENT_DATE)
I recommend that you convert your table to use an appropriate temporal datatype, such as DATE:
ALTER TABLE employee ADD COLUMN new_dob DATE AFTER dob;
UPDATE employee SET new_dob = STR_TO_DATE(dob, '%d-%m-%Y');
ALTER TABLE employee DROP COLUMN dob, CHANGE new_dob dob DATE;
(Remember also to adjust indexes, as desired).
Note that you will accordingly need to update your application code to work with DATE literals, including the previous statement:
SELECT *
FROM employee
WHERE MONTH(dob) = MONTH(CURRENT_DATE)

Use this
WHERE month(dob) = month(now)

Related

How to make a view in mySQL (phpmyAdmin) that queries table for specific date range? [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 3 years ago.
Improve this question
Essentially I want to create a view in mySQL (phpmyAdmin) that queries a table called Equipment for a date range >=2018-12-1.
This is currently what I have, it is what is wrong with my syntax?
CREATE VIEW "Equipment_Date" AS SELECT * FROM "Equipment"
WHERE "Ship_Del_Date" >= 2018-12-1;
Below query should work provided Ship_Del_Date column has datatype as DATETIME.
CREATE VIEW Equipment_Date AS SELECT * FROM Equipment
WHERE Ship_Del_Date >= '2018-12-1';
Use backticks instead of single quotes to enclose the table,column names only when the names are from mysql reserved keywords.
Use these to specify databases, tables and columns: `
And not these: "
Or simply just don't use any of these, if not necessary.
Then your SQL query will probably look like this:
CREATE VIEW Equipment_Date AS SELECT * FROM Equipment WHERE Ship_Del_Date >= 2018-12-1;

Sort data from MySQL table [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 6 years ago.
Improve this question
I have a MySQL table named camp_details which has the following columns :
camp_id, camp_name, location, category, months , pattern
I have input fields which accepts values for location, category, months and pattern.
Based on the details provided, the table should sort according to the preferences (1:location , 2:Months , 3:pattern and 4:category).
That is, the table should display first containing location, next months and so on.
Kindly help me out in this.
just use this query
SELECT * FROM camp_details ORDER BY location , months,patter,category ;
or use DESC after column name which you want to sort in desc like
SELECT * FROM camp_details ORDER BY location , months DESC,patter,category ;

how to get last updated column name from mysql [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question appears to be off-topic because it lacks sufficient information to diagnose the problem. Describe your problem in more detail or include a minimal example in the question itself.
Closed 8 years ago.
Improve this question
Is it possible to get a particular updated column name from a record?
if so, please help me. since i am creating a history table to store a updated column and their values from rest of the tables.
Please suggest me a correct way to deal this....
I believe it is not possible.
However, you can create an update trigger which monitors the table's columns and have that trigger insert records in your history table. Hope this helps.
The only way for doing this is Using something like a Log file, in this case you will create a table that will contains the updated columns each time there is an update.
In this way you will be able to get the last record that will contains the table_name and the column_name.
And you can use a query looks like that:
select id, column_name, table_name
from Log_table
order by id desc
limit 1

Can I select record in MYSQL: Sorted according to the date/time created, even if table dont have date/time stamp in it? [closed]

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 8 years ago.
Improve this question
I want to sort records in my table according to the date/time created.
But i don't have any data/time stamp column in my table.
Is there a way in which i can still select records according to the date/time created or modified???
I am using MYSQL.
I tried SELECT * from user ORDER BY created_at but this also not working.
As other commenters have pointed out, the short answer is no. MySQL doesn't allow you to sort by the time at which a record was created unless you have explicitly stored that value in the database. Here's a possible way out for the future:
ALTER TABLE users ADD COLUMN created_at DATETIME NOT NULL DEFAULT '0000-00-00 00:00:00';
ALTER TABLE users ADD INDEX created_at (created_at);
Then your future INSERT queries will add a NOW() argument to populate the created_at column.
If you do that, then when you retrieve records, if they have a "created at" value equal to the default, you'll know the record was created before you modified your INSERT query. You could go through and manually update those records, or assign them all today's date for simplicity.

How to select only workday [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Closed 8 years ago.
This question appears to be off-topic because it lacks sufficient information to diagnose the problem. Describe your problem in more detail or include a minimal example in the question itself.
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
Improve this question
I have 2 columns, date and price. The input will be 2 different dates and I want to get date and price between those (only workdays, no need to consider weekend days). How can I make this query in SQL? I really have no clue, thanks.
SELECT date, price
FROM table
WHERE date BETWEEN #start AND #end
AND WEEKDAY(date) < 5
where date_field > #start_date
and date_field < #end_date
You could also use the "between" keyword, but I always forget if that's inclusive or not.
As far as weekday goes, be very careful about using weekday(date_field) (as Barmar) suggested in the where clause as it could trigger that function being run on every row in the table which would negate any indexes you have. It's possible to use it and it be okay if the filter above is pretty stringent I think - you'll have to play with it and look at the explain statements.
There's a lot more to it than meets the eye. Really you need a calendar table per year that shows the workdays and excludes the weekends and public holidays ... which of course is region-dependent ...