sql

Why is ROW_NUMBER() not recognized in SQL Server 2008?

Why is ROW_NUMBER() not recognized as a function name in SQL Server 2008? I try this SELECT ROW_NUMBER() AS Row, Lname FROM MEN GO and I get this error: Msg 195, Level 15, State 10, Line 1 'ROW_NUMBER' is not a recognized function name. ...

Records visible but not accessible in MySQL - why!?!?!

This is a weird issue. I'm accessing my online database using premiumsofts Navicat for mysql. Some of the records are behaving very strange - let me give an example. I have the following table columns id, name, address, abbreviation, contact. Now when I run a sql query for lets say any entry that has the abbreviation 'ab' it returns zero...

MySQL query - show results that are not in another table

I have a query like this: SELECT lesson.id, p1.first_name, p1.surname, start_time, instrument.name FROM lesson, person AS p1, person AS p2, instrument, invoice_lesson WHERE lesson.student = p1.id AND lesson.teacher = p2.id AND instrument.id = lesson.instrument_id ORDER BY surname However, I would like to modify it so that it on...

[Java(J2SE)] Store data(strings) in database

I have a Vector < String >. Now i want to store those Strings in database. But i have one "but"! The program user mustn't install anything else except J2RE, he will just copy program to his computer and run. Does java has such kind of database? P.S. Previously i think about object serialization or just simple text\xml file but according...

A better logging design or some SQL magic?

I'm knee deep in modifying some old logging code that i didn't write and wondering what you think of it. This is an event logger written in PHP with MySQL, that logs message like: Sarah added a user, slick101 Mike deleted a user, slick101 Bob edited a service, Payment Broken up like so: Sarah [user_id] added a user [message], slick10...

SQL Query to Select Everything Except the Max Value

I have this rather complex query that grabs data from three tables, and now I want it to be even more complicated (Oh dear)! I'd like the last posted feature to be displayed in it's own section of the page, and that's pretty easy by selecting the last entry in the table. However, for the complex query (the main page of the site), I'd li...

Question about SQL catalogs - What exactly are they?

Something that has been puzzling me for a bit now, and an hour or two of googlin' hasn't really revealed any useful answers on the subject, so I figured I'd just write the question. When I create a database in SQL using 'CREATE DATABASE DBNAME' am I implicitly creating a catalog in that database? Is it proper to refer to that 'DBNAME' a...

What's the best way to select max over multiple fields in SQL?

The I kind of want to do is select max(f1, f2, f3). I know this doesn't work, but I think what I want should be pretty clear (see update 1). I was thinking of doing select max(concat(f1, '--', f2 ...)), but this has various disadvantages. In particular, doing concat will probably slow things down. What's the best way to get what I want?...

array structure of database results

This might be quite a trivial question, but which of these methods is best practice for structuring an array for return db results? say a list of blog posts... Sorting and grouping posts? or sorting and grouping elements? Array ( [title] => Array ( [0] => Untitled [1] => Untitled ) [id] ...

How To Do Percent/Total in SQL?

I have an typical CUSTOMER/ORDERS set of tables and I want to display the total percentage of sales a particular customer is responsible for. I can get the total number of orders in the system like so: SELECT COUNT(order_id) FROM orders And I can get the the total number of orders made by the customer like so: SELECT COUNT(order_id) ...

Plotting a Silverlight line/area graph by getting data from SQL database

Hi all. I'm very new to Silverlight and programming in general so help me out here. I want to plot a Silverlight line/area graph by getting it's coordinates from a database when the user enters some data. The graph will change its value (by pressing refresh on the browser) when the value in the database changes according to what the use...

Trying out PostgreSQL/Postgres ( I'm a common MySQL User ) - recommend any references, any gotchas?

I'm not really looking for a basic SQL guide but just something specific to PostgreSQL. And I do run my own servers so getting the latest version ( 8.2 I believe? ) is no issue. ...

How to Call a stored procedure from another stored procedure?

I have an insert SP which takes many parameters, 2 of them are @FirstName, @LastName. And have another update SP which takes manay parameters, 2 of them are @FirstName, @LastName. What i want to do is: from inside the insert SP "at its end", call the update SP and send to it the @FirstName, @LastName. I don't know the right syntax to d...

LIMIT on a condition in MySql

Hi all I am trying to get info from a table in this form : table_1 jobid(PK) projectid desc 1 1 whatever 2 1 . 3 1 . 4 2 . 5 2 . . . . . . . . . . What I am trying to get is a query wh...

How do I produce a time interval query in SQLite?

I have an events based table that I would like to produce a query, by minute for the number of events that were occuring. For example, I have an event table like: CREATE TABLE events ( session_id TEXT, event TEXT, time_stamp DATETIME ) Which I have transformed into the following type of table: CREATE TABLE ses...

Select Users with more Items

Each user HAS MANY photos and HAS MANY comments. I would like to order users by SUM(number_of_photos, number_of_comments) Can you suggest me the SQL query? ...

Bread crumbs with url rewriting

In database I have a list of hierarchical list of categories so i construct a Custom Sitemap provider (by extending StaticSiteMapProvider ) with this list of categories. Now, the page that display articles /ShowArticle.aspx?id=" + Eval("ID") is rewrited into: /id/article-title.aspx. So it's not physical exists. I want the following:...

SQL in PHP Inserting Two Rows Instead of One

The following code is inserting two records into my database, but I only want it to insert one. Why is it inserting the row twice? <? if (!$con) { die('Could not connect: ' . mysql_error()); } $i=1; while($i<=1) { if (isset($_POST['submit'])) { $sql="INSERT INTO customers (company, salutation, f...

SQL Server 2005 Query Help

I have a table and I want to get the row before the last one. Eg KeyboardID KeyboardName 1 "DELL" 2 "HP" 3 "Viewsonic" 4 "Samsung" select max(keyboardid) from keyboard -> will get the Samsung My Question is how to get the Viewsonic Keyboard... ...

Fastest Way to Import?

Dear friends! What is the fastest way to import 15000000 records from Text File to SQL Server? Currently, I am importing data using Enterprise Manager, that takes 3-4 hours for importing into the SQL table. Thanks in advance! ...