sql

postgresql database

i wanna to make a query that select users that have same username and same hour of creation date by using postgresql database ...

Extract SQL query from a Web Page independent of the Scripting language

Hello friends. At present i am doing a project regarding SQL injection. I am doing it in such a way that it will find the SQL injection independent of the server side scripting.. whether it may be jsp or asp or php. Now the major problem is I have to extract the SQL query from the web page. That is when i press submit button for instance...

How to select the MySQL's engine name of some table by sql query?

How to select the MySQL's engine name of some table. MyISAM or InnoDB. Can we do it by a simple sql query? ...

Django ORM: Getting rows based on max value of a column

Hi, I have a class Marketorders which contains information about single market orders and they are gathered in snapshots of the market (represented by class Snapshot). Each order can appear in more than one snapshot with the latest row of course being the relevant one. class Marketorders(models.Model): id = models.AutoField(primary...

How necessary or convenient is it to write portable SQL?

Time and again, I've seen people here and everywhere else advocating avoidance of nonportable extensions to the SQL language, this being the latest example. I recall only one article stating what I'm about to say, and I don't have that link anymore. Have you actually benefited from writing portable SQL and dismissing your dialect's prop...

how do i get mysql results of todays date?

I'm trying to pull results from a table that have been inserted today. Each insert is marked with a timestamp. If I do a query like: SELECT * FROM table WHERE added > DATE_SUB(NOW(), INTERVAL 1 DAY) It seems I get stuff that did fall on today's date, but also stuff from 24 hours ago. maybe I'm seeing things. I don't want to s...

How can I set the starting point for the primary key (ID) column in Postgres via a rails migration

I am deploying a rails app to heroku which uses PostgreSQL as its back-end. In my database migration I normally set the ID field for things likes reports etc to at least 1000, most clients don't seem to like starting at 1. Normally I use mysql and I simply add an sql specific after my table creation: def self.up create_table :repor...

SQL Server Syntax to select two rows of data and overwrite values that are different from the first row

Hi, I have a table that looks like the following: id, Name, LinkBackId, Param1, Param2, Param3 1, "Name1", NULL, 10, 20, 30 2, "Name2", NULL, 10, 20, 30 3, "Name3", 2, 14, NULL, NULL The LinkBackId is important here because this is associated with the id that is also in th...

insert data in increments

Does anyone know how to insert data into a table in increments of about 1000? I have a table with thousands of records that I want to insert into an identical table on a different server. ...

Problems using MySQL FULLTEXT indexing for programming-related data (SO Data Dump)

I'm trying to implement a search feature for an offline-accessible StackOverflow, and I'm noticing some problems with using MySQLs FULLTEXT indexing. Specifically, by default FULLTEXT indexing is restricted to words between 4 and 84 characters long. Terms such as "PHP" or "SQL" would not meet the minimum length and searching for those t...

Compare dates in T-SQL, ignoring the time part

I'm using MS SQL 2005, and I want to check two dates for equality, but ignoring the time part. I know I can make use of DATEDIFF, but am concerned that it may be slow - this SP gets used in the DB a lot! Any suggestions? Edit: David Andres' comment: '"comparison" includes much more than equality' made me realise that I didn't make my...

Management Studio 2005: Will Cancelling a Statement trigger a Rollback?

A few minutes ago, while working out a new sproc, I executed the wrong delete statement. Something like this: Delete From SomeTable Where SomeStatusID=1 10 seconds into it, I realized that I typed in the wrong status and hit cancel. It said that the statement was canceled. I did a restore to a separate database to get back the table ...

Get permissions for stored procedure in sql server 2005

How do I get the granted permissions for a stored procedure in sql server 2005? ...

Oracle Duration Function

Why isn't my PL/SQL duration function working correctly? In the query below, I manually calculate the 'hh:mm' the same way as in the function below. However, I get different results. Calling Query: WITH durdays AS (SELECT SYSDATE - (SYSDATE - (95 / 1440)) AS durdays FROM DUAL) SELECT TRUNC (24 * durdays) AS durhrs, MOD (TRUNC ...

SQL: What does =* mean?

I'm trying to trace some SQL in Microsoft Server. I came across a join that is using a convention unfamiliar to me. What does "=*" mean? WHERE table1.yr =* table2.yr -1 ...

How to escape a string for use with the LIKE operator in SQL Server?

I am looking for something that works in SQL Server similar to the @ symbol in c# which causes a string to be taken as it's literal. Eg: string text = "abcd\\efg"; Output of text = abcd\efg string text = @"abcd\\efg"; Output of text = abcd\\efg Note how the @ affected the string to take every character as is. Now I am not sure this...

if(condition, then, else) in Oracle

Hey all, MySQL/MSSQL has a neat little inline if function you can use within queries to detect null values, as shown below. SELECT ... foo.a_field AS "a_field", SELECT if(foo.bar is null, 0, foo.bar) AS "bar", foo.a_field AS "a_field", ... The problem I'm running into now is that this code is not safe to run on an Oracle database,...

How to ORDER BY based on two different columns

I have a table with 5 columns. When I list the table, I want to order by one column so that the types are grouped together and then order them alphabetical so that they are easy to find. Is it possible to ORDER by two different columns? Here is my current select: $query_rs_cms = "SELECT * FROM games ORDER BY type ASC"; I guess wha...

Is InnoDB sorting really THAT slow?

I had all my tables in myISAM but the table level locking was starting to kill me when I had long running update jobs. I converted my primary tables over to InnoDB and now many of my queries are taking over 1 minute to complete where they were nearly instantaneous on myISAM. They are usually stuck in the Sorting result step. Did I do som...

Comparing two database tables

I need to compare ALL fields in two tables... they are the same size (four lines) and have the same amount of columns (five columns). The logic I'm looking for is... If (table 1 = table 2) do something Else do something else In SQL I wrote something like... If (Select * from table 1 = select * from table 2) do something else do somet...