Skip to content

Tag: sql

mysql allow invalid dates on select

For some reason, I can’t even select invalid dates in my table. How do I force select? I just receive: select * from table >> Mysql2::Error: Invalid date: 1900-00-00 I’m not trying to insert, …

Query using ILIKE with IN

Is it possible to run a query using ILIKE with the IN function? For example: I want to run the results returned from the nested query through the ILIKE function. Is there a way to do this? Answer Can be simpler: You can check the resulting query plan with EXPLAIN ANALYZE. You may need to add leading and trail…

MySQL ON DUPLICATE KEY UPDATE syntax error

I was wondering if anyone can spot any mistakes in my sql statement. I would like it to insert a new record into my table if one doesn’t exists already. If it does exist then just update it. My primary key in the date field. Here is my statement as it appears in php and also the error I’m getting:

SQLalchemy specify which index to use

Is there a way in SQLalchemy to tell the query which index to use? The reason I need this is that the SQL queries it generates use the “wrong” index – there exists an index for exactly the two fields that I have and it doesn’t use it. Thanks! Answer I think you can use with_hint() for …

group rows in plain sql

I have a Table with columns Date and Number, like so: date Number 1-1-2012 1 1-2-2012 1 1-3-2012 2 1-4-2012 1 I want to make a sql query that groups the rows with the same Number and take the minimum date. The grouping only may occur when the value iof Number is the same as previous / next row. So

Issue creating table in MS SQL Database with Python script

The above code successfully connects to the database. The script also returns no errors when run, however when I go to check if the table was created, there are no tables in the SQL DB at all. Why is no table created and why is no error returned? Answer Each user in MS SQL Server has a default schema associat…

Delete with “Join” in Oracle sql Query

I am not deeply acquainted with Oracle Sql Queries, therefore I face a problem on deleting some rows from a table which must fulfill a constraint which includes fields of another (joining) table. In other words I want to write a query to delete rows including JOIN. In my case I have a table ProductFilters and…

Is there a way to change DATE format on?

I need to store some date in my SQL database, the problem is that the default storage is And I need My only solution was to store date as Varchars (10) and it’s working pretty well, but now I can’t order my queries by DATE, and I need to order them from the oldest to the newest… Answer There…