sql

Mysql Error: #1247 - Reference 'karma' not supported (reference to group function)

Here is my mysql query below. Through many helpful questions and comments I am almost at the end of my journey. The idea behind this query is a user submits a link, the application inserts two rows, one into links and another into votes (a default vote, why wouldn't a user vote for their own submission?) Then every vote is just anothe...

Combining the following mulitple SQL queries into 1 with MS Access & ASP

I want to combine Select top 2 scouting.* From scouting Where scouting.astroLoc Like 'D01%' AND scouting.ownerGuild = 'SWARM' Order By scouting.jumpGate Desc with Select top 2 scouting.* From scouting Where scouting.astroLoc Like 'D02%' scouting.ownerGuild = 'SWARM' Order By scouting.jumpGate Desc with Select top 2 scouting.* Fr...

How does mySQL handle dynamic value within ORDER BY

It stumbled upon me while I was reading the query in another post. Take the following query for example (ignore the non-practical use of the ordering): SELECT * FROM Members ORDER BY (TIMESTAMPDIFF(FRAC_SECOND, DateCreated , SYSDATE())) Say "Members" table has a huge row count (or the query is complex enough for it to be executed o...

Trouble with chaining joins

I was wondering if someone could help me with chaining joins - I'm not understanding the thought process. An example with three tables: ArticleCategories ----------------- CategoryID CategoryName Articles --------- ArticleID ArticleText CategoryID (FK) ArticleComments ----------------- CommentID ArticleID (FK) CommentText I have ...

How to use CONTAINS with inline queries in SQL Server 2008?

I have this sql query where I'm trying to use CONTAINS to search the title field. But I get this error. "Cannot use a CONTAINS or FREETEXT predicate on column 'Title' because it is not full-text indexed." The Titles table has been indexed and a CONTAINS works fine with a simple search. Does anyone know what I'm doing wrong? Are CONTA...

Is there any Ruby framework to return database data to XML?

Instead of writing the SQL query, is there any lazy way to get the data from database in XML format. ...

inner joins in oracle

I was thinking about the syntax of inner joins in Oracle's SQL implementation and here is something that seems a bit inconsistent: Let's say you have two relations loan(loan_number, branch_name, amount) and borrower(customer_name, loan_number). loan_number is the attribute common to both tables. Now, Oracle gives you two ways to express...

omit the first 5 rows?

I want to SELECT all rows except for the first 5 rows in a table. How do I do that? Why cant I just type $query = "SELECT * FROM ages OFFSET 5 ORDER BY id ASC"; ...

what patterns allow for object persistance using sql and nosql databases?

With the rise of the nosql movement we see different options for storing objects. Are there object persistence patterns that can handle both sql and nosql backends and allow to easily switch between the two? ...

SQL syntax error using Python and psycopg

How can you fix this SQL-code? My Python code: import os, pg, sys, re, psycopg2 conn = psycopg2.connect("dbname=tk user=masi password=123") cur = conn.cursor() cur.execute("""INSERT INTO courses ('course_nro') VALUES ( `:1` )""", ['hen']) I get: Traceback (most recent call last): ...

Search function, SQL Server

Hello! I am creating a small search function on my site, this enables the search for articles in the system. Each article has a set of keywords associated to it and these keywords are stored inside a SQL Server database. This is the table: CREATE TABLE [dbo].[SearchWords] ( [ID] [int] IDENTITY(1,1) NOT NULL, [ArticleID] [int] ...

SQL: Looking up the same field in one table for multiple values in another table?

(Not sure if the name of this question really makes sense, but what I want to do is pretty straightforward) Given tables that looks something like this: Table Foo --------------------------------- | bar1_id | bar2_id | other_val | --------------------------------- Table Bar -------------------- | bar_id | bar_desc| -------------------...

Update of AccessDatasource does nothing but has no error

My UPDATE command fails to change any date in the table while very similar SELECT and DELETE commands work. When I change the UpdateParameters to invalid choices, the code behind command throws an error, buy when the parameters are correct, nothing hapens. Code behind to activate DELETE (which works) protected void Button2_Click(objec...

Why is Linq To Sql databinding to gridview much slower than pass-through SQL?

Hello, I have compared two queries which fetch some fairly large data from a database table. For query one I used Linq To Sql and for the other I use passthrough SQL via ADO.NET. I know that Linq To Sql has to do a lot of work behind the scenes, but what is it actually doing? The two queries fetches the same amount of data but the Linq...

Finding data closest to date?

I have a table CREATE TABLE `symbol_details` ( `symbol_header_id` int(11) DEFAULT NULL, `DATE` datetime DEFAULT NULL, `ADJ_NAV` double DEFAULT NULL ) with ~20,000,000 entries. Now I want to find the ADJ_NAV value closest to the end of the quarter for just one symbol_header_id: SET @quarterend = '2009-3-31'; SELECT symbol_head...

Query causes mysql server to go away

We have an application that has been deployed to 50+ websites. Across these sites we have noticed a piece of strange behaviour, we have now tracked this to one specific query. Very occasionally, once or twice a day usually, one of our debugging scripts reports 2006 : MySQL server has gone away I know there are a number of reasons this...

Adding a column to all user tables in t-sql

I need to add a delete flag column to all 40 user tables in a database. I could write a script to loop through sys.tables, but I thought I'd check and see if anyone has either a better solution, or pre-created sql for this scenario. ...

SSIS Intermittent variable error: The system cannot find the file specified

Our SSIS pacakges a structured as one Control package and many child packages (about 30) that are invoked from the control package. The child packages are invoked with Execute Package Task. There is one Execute Package Task per child package. Each Execute Package Task uses File Connection Manager to specify path to the child package dts...

Postgres math expression calculcated for each row in table

Using PostgreSQL, supposing a table like the following: 12184 | 4 | 83 12183 | 3 | 171 12176 | 6 | 95 How can I compute a math expression for each row in the table? For example, to divide column 2 by column 3, such that the output would be: 12184 | 0.04819277...

Calculating from self-join

I have a list of values and dates for stock ticker symbols and want to calculate quarterly returns in SQL. CREATE TABLE `symbol_details` ( `symbol_header_id` INT(11) DEFAULT NULL, `DATE` DATETIME DEFAULT NULL, `NAV` DOUBLE DEFAULT NULL, `ADJ_NAV` DOUBLE DEFAULT NULL) For fixed quarter start and end dates that works fine: set...