sql

Conditional insert as a single database transaction in HSQLDB 1.8?

I'm using a particular database table like a "Set" data structure, i.e., you can attempt to insert the same row several times, but it will only contain one instance. The primary key is a natural key. For example, I want the following series of operations to work fine, and result in only one row for Oklahoma: insert into states_visited...

How to list non existent items?

Hi, the title might be a little bit confusing, let me explain, ;) I have 3 tables: [names] n_id;name 1;Jeff 2;Adam [books] b_id;title 1;Book1 2;Book2 [read] n_id;b_id The table [read] is a table with read books. if Adam reads "Book1" the item in [read] looks like this: 2;1 so far, so good. Now, is there a way to know which books ...

Oracle Query - Get only strings in the select field

Hi all! Maybe this sounds a little bit crazy, but I need to come up with a query to retrieve only letters out of an alphanumeric field. For example: TABLE 1234ADD 3901AC 1812OPA 82711AUU RESULTS EXPECTED ADD AC OPA AUU Thank you! ...

Can I concatenate a virtual column in a view?

Unfortunately, I have plaintext passwords in a database. I want to pass these plaintext values around as little as possible for, say, comparisons and updates. To this end, I'm trying to create a view of my Users table that excludes the plaintext passwords and instead provides a hashed value of that password. Here's my current SQL Serv...

SQL Count for a Date Column

Hi folks I have a table that containts a set of columns one of it is a Date column. I need to count how many occurrences of the values of that column refer to the same month. And return if for one month, that count sums more than 3. For example: ____________________ | DATE | .... | --------------------- 1998-09-02 1998-09-03 19...

insert many rows with one static field and fields selected from another table

what i am trying to do is this: INSERT INTO Table1 (id1, id2) ( SELECT id, 1 as id2 FROM Table2 ) except i CANNOT put '1 as id2' inside that select statement. so, as an example, i sort of want this: INSERT INTO Table1 (id1, id2 = 1) ( SELECT id FROM Table2 ) i'm putting this in a stored proc and the select statement is gen...

I'm making a resume...what would you consider as intermediate python programming skills?

I've made a couple of scripts. One is a stock screener that can search through every stock. Another creates a heatmap that tells you what's performed well and badly over the past day. They aren't really that useful, just did them to work on my programming skills. I was able to throw some SQL in my scripts too. Would you call that in...

How do I do a "like" wildcard comparison in Entity Framework in .NET 4.0?

I'm using the Visual Studio 2010 RC for .NET 4.0 and I'm trying to figure out how to do a wildcard comparison with Entity Framework. I'd like to have the following query for EF where I find all the names that start with 'J' select * from Users where FirstName like 'J%' ...

In which SQL dialect was RANK() first introduced?

In which SQL standard was RANK() first introduced? List of SQL standards: SQL-86 SQL-89 SQL-92 SQL:1999 SQL:2003 SQL:2008 SQL Rank function: http://en.wikipedia.org/wiki/Select_(SQL)#RANK.28.29_window_function References would be most appreciated. ...

30 million records. Divy them up into 24 hourly-periods. Sum them for one month. Rinse and Repeat.

Hi!, I need to examine 30 million records (one month worth) of daily ticket validations (Unix datetime) and divy them up into 24 one-hour periods for 211 stations. First I created a view which selects the month I’m looking for (and the equipment type) then creates a Windows Datetime value for each Unix datetime. SELECT TOP (100) PERCE...

Executing an Oracle Stored Proc as Another User...

I'm mostly an oracle novice, so forgive me if this is a stupid question... I have a schema called 'CODE' with a stored proc that executes arbitrary SQL (for now, please ignore the potential security issues associated with that). The SQL that is passed in will select data; but all of the data resides in either schema A, B, or C - but th...

Virtual table ...

CREATE TABLE #Report( Cell int, CellValue double) Error here DECLARE @Report TABLE ( Cell int, CellValue double) And here So ... how to work with virtual table :S and why error ...

count of a value in a column in mysql database

i have a large mysql database table in which one column contains values ranging from 1 to 9 what query can i give so that i can get the count of 1s and 2s and 3s ... 9s in that column in the database ? ...

select from one table and insert into another

I've got two tables. Table_A (nid, vid, type, title, uid) Table_B (id, questiontext) I need to insert records from Table_B into Table_A. I tried this: INSERT INTO Table_A (nid, vid, type, title, uid) VALUES ('', '', multichoice', (SELECT questiontext from Table_B), '1') but it's throwing an error. What should be the correc...

Select DataTable (only some values) from ???_GetDisplayData and GROUP data by days where group rules is different for different columns

Hello dear Stack-Overflow :3 I've got a kind of hard-case question. So I'll try clearly explain my idea with my poor english :/ need select to DataTable SOME values from ???_**GetDisplayData **procedure for each day of previos month (GROUP IT) where group rules for different columns is different I need to select some valu...

Optimizing simple SQL query?

Greetings friends, In my MySQL database, I have 'MAB' table which contains information about Gene Ids (GI_ID),and some other gene related information. 'MAB_CAN' table can contains the Gene Ids (GI_ID) only relevant to Cancer. I use following SQL query to get cancer related information from MAB table : SELECT * FROM MAB WHERE `GI_ID` ...

SELECT NAME FROM ABCD WHERE NAME LIKE "+aero+%"AND ROWNUM <= 10

SELECT NAME FROM ABCD WHERE NAME LIKE "+aero+%"AND ROWNUM <= 10 what is the syntax error in this line......SELECT NAME FROM ABCD this is working ...

How to club the results of two SQL queries?

SELECT * FROM( (SELECT count(DISTINCT RECEPIENT_ID) as NoOfUsers, TO_CHAR(ACTN_TAKE_DATA_TM,'YYYY-MM-DD') as accDate FROM ALRT_PLATFORM_ALRT_HSTRY where APPL_CD like 'EBP' and ALRT_RSPNS_FROM_CLIENT_ID like 'BB' group by TO_CHAR(ACTN_T...

Why SQL variable still keep previous value ?

I notice a strange thing during doing some stored procedures I can explain that by the following example : DECLARE @FileExtensionID int SELECT * FROM FileExtensions WHERE (Name= 'pdf') SELECT @FileExtensionID = ID FROM FileExtensions WHERE (Name= 'pdf') SELECT IsNULL( @FileExtensionID , 0) -- First Select SELECT * FROM FileExtensions...

Oracle Timestamp: extract full hour

I need to extract the 'full' hour of a timestamp. Like for 2010.03.04 13:13 I want 2010.03.04 13:00 (as a timestamp again). My current approach is: TO_TIMESTAMP(TO_CHAR(m.begin, 'yyyy.mm.dd hh24'), 'yyyy.mm.dd hh24') Is this really the way to go? Who good/bad does it perform (I plan to do a GROUP BY on it). Thanks for your input! ...