I want to subtract between two date time values using SQL in MySQL such that I get the interval in minutes or seconds. Any ideas? I want to run a SQL query that retrieves uses from a database who have logged in like 10 minutes from the time. Answer There are functions TIMEDIFF(expr1,expr2), which returns the …
MySQL INTO OUTFILE override existing file?
I’ve written a big sql script that creates a CSV file. I want to call a cronjob every night to create a fresh CSV file and have it available on the website. Say for example I’m store my file in ‘/…
What SQL would I need to use to list all the stored procedures on an Oracle database?
What SQL would I need to use to list all the stored procedures on an Oracle database? If possible I’d like two queries: list all stored procedures by name list the code of a stored procedure, given …
Sqlalchemy complex in_ clause with tuple in list of tuples
I’m trying to find a way to cause SQLAlchemy to generate a query of the following form: select * from t where (a,b) in ((a1,b1),(a2,b2)); Is this possible? If not, any suggestions on a way to …
Using column alias in WHERE clause of MySQL query produces an error
The query I’m running is as follows, however I’m getting this error: #1054 – Unknown column ‘guaranteed_postcode’ in ‘IN/ALL/ANY subquery’ My question is: why am I unable to use a fake column in the where clause of the same DB query? Answer You can only use column ali…
Copy Data from a table in one Database to another separate database
Basically I have a two databases on SQL Server 2005. I want to take the table data from one database and copy it to another database’s table. I tried this: This didn’t work. I don’t want to use a restore to avoid data loss… Any ideas? Answer SELECT … INTO creates a new table. You…
MySQL dump by query
Is it possible to do mysqldump by single SQL query? I mean to dump the whole database, like phpmyadmin does when you do export to SQL
How can I detect a SQL table’s existence in Java?
How can I detect if a certain table exists in a given SQL database in Java?
Use bcp to import csv file to sql 2005 or 2008
I have a csv file and i need to import it to a table in sql 2005 or 2008. The column names and count in the csv are different from the table column names and count. The csv is splitted by a ‘;’ . Example CSV FILEcontents: SQL Person Table Answer I’d create a temporary table, bulk insert the …
What is the difference between JOIN and UNION?
What is the difference between JOIN and UNION? Can I have an example?