I have two date columns – from_date and to_date in a database table. Example: from_date: 2012-09-10 to_date: 2012-09-30 today: 2012-09-13 I need to fetch all records, if today’s date is between from_date and to_date. How do I do that with a SQL query? If I have loaded the respective record, I can …
Tag: sql
SQL query to find Primary Key of a table?
How can I find which column is the primary key of a table by using a query?
How to get the last row of an Oracle a table
I want to get the last row, which I inserted into a table in an Oracle 11g Express database. How can I do this? Answer There is no such thing as the “last” row in a table, as an Oracle table has no concept of order. However, assuming that you wanted to find the last inserted primary key and that
How to separate DATE and TIME from DATETIME in MySQL?
I am storing a DATETIME field in a table. Each value looks something like this: 2012-09-09 06:57:12 I am using this syntax: Now my question is, while fetching the data, how can get both date and time separately, using a single MySQL query? Date like “2012-09-09” and time like “06:57:12”…
Using a SQL source file with the bigquery cli
Is it possible to use an input file with the bigquery CLI? Answer If you’re using unix (or have cygwin installed on windows), you can use xargs: Alternately you can use back-ticks: Note that bq can only process one command at a time — if your .sql script has several queries, you’ll need to s…
How to replace (null) values with 0 output in PIVOT
I tried to convert the (null) values with 0 (zeros) output in PIVOT function but have no success. Below is the table and the syntax I’ve tried: I tried to use the ISNULL but did not work. What syntax do I need to use? Answer
MSSQL cast( [varcharColumn] to int) in SELECT gets executed before WHERE clause filters out bad values
Assume the following schema and query: Please look past the glaring design issues with having values in a varchar column that we expect to be ints. The break: We get a cast break due to a value that cannot be converted to an int. In this case: “123-1”. The strange thing is that the value being cas…
SQLite over LAN
my application uses SQLite database for it’s data storage. Idelly, this database should reside on some network drive, let’s name it Z: (Windows XP’s “Map network drive” feature). Application is being developed under Linux, with database locally stored. Here is a part of one modul…
Find most frequent value in SQL column
How can I find the most frequent value in a given column in an SQL table? For example, for this table it should return two since it is the most frequent value: one two two three
Check if datetime is in current date
I am using SQLServer 2008. I have a table X with field Y that is a datetime format. In the WHERE statement of my query I only want to keep the rows where the date of field Y equals the current date. …