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
Sorry im just new to mysql and php world. can someone help me?
There is an error of
You have an error in your SQL syntax; check the manual that
corresponds to your MySQL server version for the right syntax to use
near 'AND NOT= End_date LIMIT 0, 30' at line 1
This is the sql code
SELECT * FROM config_modi_ord WHERE Start_date < && != End_date
Are you using datetime or just date fields? If you're comparing datetime fields that fall on the same day, but different times, then you will get some that appear to fall on the same day. If you just want to compare the date component only, you can extract it using the date() function, so try this:
select * from config_modi_org where date(date_acknowledge) > date(end_date)
If that still isn't what you want, then you really need to add your table schema, some sample data and your exact query to the question.
You need to specify the column you are planning to use, in all filter conditions.
Try this.
SELECT * FROM config_modi_ord WHERE Start_date < End_date
Related
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 1 year ago.
Improve this question
I want to get some records using SELECT Statement from this table:
my table
My SELECT Statement:
$getDates="SELECT daily_rate_date, daily_rate_price FROM daily_rates WHERE daily_rate_date >= '".$checkOut."' AND daily_rate_date < '".$departureDate."' AND daily_rate_reservation=$reservationId;";
When I echo this query It shows this:
SELECT daily_rate_date, daily_rate_price FROM daily_rates WHERE daily_rate_date >= '2021-03-03' AND daily_rate_date < '2021-03-08' AND daily_rate_reservation=65;
The problem is that when I use this query in Xammp it does not return all the results that i need as you can see in the next picture:
result
It looks like your SQL query is doing exactly what you want it to do; looking for daily_rate_dates between 2021-03-03 and 2021-03-08. If you want daily_rate_id then your SQL query should look like this:
$getDates="SELECT daily_rate_id, daily_rate_date, daily_rate_price
FROM daily_rates
WHERE daily_rate_date BETWEEN {$checkOut} AND {$departureDate}
AND daily_rate_reservation={$reservationId};";
If you're looking for those rows in a different month, well your parameters are off. Additionally, you should use prepared statements instead of this direct querying.
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 5 years ago.
Improve this question
I have a mysql record with the columns start_date and end_date. Now I have a date (as example 2017-08-03) and i want to ask if this date is between the start_date and end_date in my mysql table.
Is this possible?
Use between:
SELECT * FROM events
WHERE '2012-01-18' between start_date AND end_date
BTW: Take care of time part if start and end are datetime types
You can use this:
SELECT * FROM events
WHERE start_date<='2012-01-18'
AND end_date>='2012-01-18'
SELECT *
FROM `yourtable`
WHERE (your_found_date BETWEEN 'start_date' AND 'end_date')
Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 6 years ago.
Improve this question
I make some website which will be similar to basic TODO List applications. For a single row I always store single date and I basicly dont need hours and seconds, date is just fine.
How I use data:
I have PHP backend which make SQL select and then create JSON from this data and give it frontend which is created in AngularJS.
What I want to do with data:
I want to compare data and visualize it with graphs. I am not sure whats the best way to store this kind of values.
Things I consider:
Unix TIME - I feel like its really easy to work with numbers in any language and also easy to compare and visualize
MySQL Date - I'm not sure because I think that inside MySQL date format should be really usefull but I'm not sure how to compare date in format like: YYYY-MM-DD
MySQL Datetime - Basicly same as before just with added time, I dont think this can be usefull for me.
I will be really happy your opinion and advise which can help me. Also advantage of each method because I mentioned just advantage of UNIX TIME because number are easy to compare. It's also easy I miss something relevant how to store date in database so if there is other option please don't hesitate to speak about it.
Thanks
I would opt for MySQL Date.
Lets say we have a table called my_table which has a Date column named my_date.
You can actually interact with it in much the same way as you can a timestamp. Assuming my_date is the date that the item was created...
// Where it was created after 1st Jan
SELECT * FROM my_table WHERE my_date > '2016-01-01'
// Where it was created in Jan
SELECT * FROM my_table WHERE my_date BETWEEN '2016-01-01' AND 2015-01-31
// Where it was created in the last 7 days
SELECT * FROM my_table WHERE DATEDIFF(CURDATE(), my_date) <= 7
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 6 years ago.
Improve this question
I'm using this query :
select field from table1 where time LIKE '%2016-03%' order by time asc limit 1
My problem is that the table has thousands of rows and so it takes too long to search for 1 row. Is it normal?
LIKE queries are always going to be slower than looking for a specific value.
It'll help immensely to add an INDEX on the field and change your query to LIKE '2016-03%' (there won't ever be anything before the year in a timestamp so drop that first %). It'll be able to take a couple shortcuts, at least.
If you use LIKE and starts with % MySQL must make a FULL TABLE SCAN to find the correct Dates, but if you start direct with the year they can use a index : ... KIKE '2016-03-%'
Try adding an INDEX to your time column and as other have pointed out, remove the leading % from the query.
See this post for more info
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 8 years ago.
Improve this question
How to get best time from MySql table collumn which I made varchar (I can change it, just I didn't know better) which data looks like "00:05:22.22" (it's "hours:minutes:seconds.milliseconds").
it's like laps times in that collumn..
or I should change my DB table structure? to what?
and how I should do it then?
i.e.
in that collumn are records like this:
00:00:04.99
00:00:04.57
00:00:04.55
00:00:04.58
00:00:03.36
And I would like to get all of them ordered by shortest time. Like best lap.
If you are using MySQL 5.6.4 or greater, you can use the TIME datatype for your column and indicate that it should accept fractional parts of a second - see here.
Otherwise, using a VARCHAR column, you can still use the MIN/MAX functions for your data and expect to get a valid result (provided all values are correctly formatted), since alphabetically sorting the data in your use case should give the same result as numerically sorting it.
Alternatively, you can use the ORDER BY clause on that column and take just the first n results. Depends on your needs.
To get an ordered set from a table your query needs to specify an order -
SELECT *
FROM `table`
ORDER BY `lap_time` ASC
You do not have to include ASC in the query as any ORDER BY will sort from smallest to largest unless otherwise told not to do so with DESC
As you have said, your column datatype is varchar, you can do
select [column_names] from [table_name] order by [column_name_containing_time] asc
You can see an example here: SQL Fiddle