If I have a person’s date of birth stored in a table in the form dd-mm-yyyy, and I subtract it from the current date, what format is the date returned in? How can I use this returned format to calculate someone’s age? Answer If the value is stored as a DATETIME data type: Less precise when you con…
Tag: sql
Caching SQL queries
If I look in my profiler for SQL-server, it comes up with a lot of duplicate queries such as: A lot of these queries are not needed to display real time data, that is, if someone inserted a new record that was matched in that query it wouldn’t matter if it didn’t display for up to an hour after in…
Importing records from PostgreSQL to MySQL
Was wondering if anyone had any insight or recommended tools for exporting the records from a PostgreSQL database and importing them into a MySQL database. I believe the table structure is 100% identical. Thoughts? Thanks! Answer The command will generate SQL-standard-compliant INSERT statements with all colu…
PostgreSQL visual interface similar to phpMyAdmin?
I’d like to view and possibly edit tables for PostgreSQL visually like phpMyAdmin, where you can see the list of tables, and fields and individual rows for a table. Is there any utility that can do this? Forgive me if this is actually possible in pgAdmin III, but I couldn’t figure out any way to s…
sqlite variables
Greetings! I am using SQLite. I want to declare variable, but it gives me a syntax error. Please help me to find a solution: Select * from t2 where value= ? This is my query. Now how can I pass …
Select NULL Values in SQLAlchemy
Here’s my (PostgreSQL) table — I want to select all people that are not known to be married, i.e., including those with NULL marriage_status. This does not work — Of course this does — The problem is that I’m accessing it from SQLAlchemy with — which gets translated to R…
Join query on Date Range
HI I have following tables and so on for whole year I want the following output I need to take join between these two tables but i couldn’t figure how join condition will be look like Ragards Answer
Complex JOIN with ActiveRecord and Rails 3
I have the following models: I have to find all posts that belong to groups where user is a member. I have made it with this method: but it produces unefficient SQL: I want to make a query like this: How can I do this without using raw SQL? Answer something like this should work for you, although it requires
SQL SELECT clause tuning
Why does the sql query execute faster if I use the actual column names in the SELECT statement instead of SELECT *?
Inserting into Oracle and retrieving the generated sequence ID
I have a handful of raw SQL queries for SQL Server which use SCOPE_IDENTITY to retrieve the generated ID for a specific INSERT immediately after that INSERT occurs all in one execution… The question is: What’s the best way to do that for an Oracle database? Can this be done on Oracle through standard SQL or d…