sql

postgres group by aggregate function

I have a messages table which looks like this: +------------+-------------+----------+ | sender_id | created_at | message | +------------+-------------+----------+ | 1 | 2010-06-14 | the msg | | 1 | 2010-06-15 | the msg | | 2 | 2010-06-16 | the msg | | 3 | 2010-06-14 | the msg | +----------...

Extended placeholders for SQL, e.g. WHERE id IN (??)

Bounty update: Already got a very good answer from Mark. Adapted := into :, below. However, I'm still looking for similar schemes besides DBIx. I'm just interested in being compatible to anything. I need advise on the syntax I've picked for "extended" placeholders in parameterized SQL statements. Because building some constructs (IN c...

Constraining combo box rows to field entry of the same entry

I have three related tables: People has ID fields for both Organisations and Locations. Locations has an ID field for Organisation. I want the Locations combo box in my People table to show only the Locations that have the Organisation_ID that was entered previously. I tried WHERE but it doesn't seem to recognise the [People].[Organisati...

SQL Server 2008 - HashBytes computed column

Hello, I'm using SQL Server 2008. I have a NVARCHAR(MAX) column called Title and i want to add an unique index for it. Because the column is bigger than 900bytes , I decided to create a HashBytes computed column (based on recommendation on StackOverflow). How do i create the HashBytes column? alter table Softs add TitleHash AS (has...

PHP code to update MySQL table

I want to update a MySQL table with information from two other tables. I'll set up a cron job, but I don't know what PHP code to use. Every time the cron job runs, I want the 'VideoNumber' column from the 'Profiles' table to be updated with the amount of videos they've uploaded to the site. Video information is stored in a table called...

SQL query a new thread in vBulletin

Hello. How to make a query to the database(mysql) to create a thread? I need to create a thread from a non-registered user, if not, then from the present .. Simply query the database with the subject "Test", the text "test text" and any nickname Sorry for bad english, thank you! ...

Improving efficiency of SQL selects and joins in sqlite

I'm working on a personal project focusing on analysis of text in a database. My intent is to do something interesting and learn about SQL and sqlite. So with my novice abilities in mind, I'd like to get advice on doing this more efficiently. Say, for example, I want to pick out the types of food in an article A. I parse my article, ...

Cancel insertion inside a trigger without a rollback.

For a certain assignment, I'm tasked with creating a very simple Q/A site, complete with tagged questions and commented answers. One of the requirements is to have a trigger to detect the insertion of duplicate tags and, if such is the case, increment the already-existing tag's usage counter. Problem is, I can't cancel the trigger with...

SQLAlchemy Select statement - SQL Syntax Error

I have created a table (MySQL 5.1) from sqlalchemy import * def get(): db = create_engine('mysql://user:password@localhost/database') db.echo = True metadata = MetaData(db) feeds = Table('feeds', metadata, Column('id', Integer, primary_key=True), Column('title', String(100)), Column...

SQL: Comparing a whole row of data to a number

I'm basically logging data to an SQL database every minute, but I want to be able to check to see if there are any entries missing (ie: see if there are any differences greater than a minute). Take this for example: 5 4 2 1 I would want to display the rows where the 4 and 2 exist so that I know there is something missing between. The ...

Pros/Cons of storing serialized hash vs. key/value database object in ActiveRecord?

If I have several objects that each have basically a Profile, what I'm using to store random attributes, what are the pros and cons of: Storing a serialized hash in a column for a record, vs. Storing a bunch of key/value objects that belong_to the main object. Code Say you have STI records like these: class Building < ActiveRecord:...

Convert Date Format

User updated in Excel as 01-03-2010 (as in DD-MM-YYYY). How do I covert this into YYYYMMDD in SQL? I have tried using FromDate=Format(Sheet1.Range("A3"),"yyyymmdd") and when I executed the SQL statement, it doesn't show any result. ...

Postgresql Application Insertion and Trigger Performance

I'm working on designing an application with a SQL backend (Postgresql) and I've got a some design questions. In short, the DB will serve to store network events as they occur on the fly, so insertion speed and performance is critical due 'real-time' actions depending on these events. The data is dumped into a speedy default format acros...

SQL to calculate distinct count for a desired table.

id1 id2 year State Gender ==== ====== ====== ===== ======= 1 A 2008 ca M 1 B 2008 ca M 3 A 2009 ny F 3 A 2008 ny F 4 A 2009 tx F This is the table i have, I need to find the total No of distinct Count in this t...

SQL server : XML : Data Base Table Optimization

I have a SQL server DB , which have a Table , which Log every Exceptions with details along with 2 XML's (1 for Request , 1 for Response). These 2 XML's are Compressed. Now as the Data volume is high , I need to clean the Table in every 3-4 month. What are the Optimization technique , I can use to avoid Data Clean up's. ...

Is my path of learning data mining correct

Someone has just told my boss what data mining can do to a company like recommendation , predictive modelling. Basically we are a website company. I am going on leave for 6 months. So my boss said that I can learn some DM techniques so that when I come back we can visit small shops or small companies to provide them with predictive data ...

How to rename database without deleting or moving tables in mysql?

Possible Duplicate: How do I quickly rename a mysql database (change schema name)? hi , plz help me to rename the database name in mysql ...

Implementing arrays in MySQL

Is there any provision for creating arrays (variable length would be preferable) in MySQL . I need to create 2-3 lists for each user and update/append/delete items from the lists . How do I implement them? . Creating tables for each user will lead to a total mess in my opinion, but anyway I'm new to MySQL so please help me out . Thanks ...

SQL Server: how to query when and where (which database) logins take a connection?

I have many databases in one SQL Server instance. Also I have many individual domain users for logins and also domain groups as logins. These logins are attached to databases as database users. Now I would like to create a report (or a query) to find out when and where (which database) these logins take a connection. I tried to find this...

Tutorial for speeding up SQL queries?

Is there a good tutorial out there how to speed up/refactor SQL Queries? I googled a bit, but did not find anything useful. Thanks :-) ...