sql

How to parse out quoted values from a column with sql

I have a field that has values like this... s:10:"03/16/1983"; s:4:"Male"; s:2:"No"; I'd like to parse out the quoted values. its going to be some sort of combination of substr and instr its the doublequote i have issues finding its position. i have tried things like select substr(field_value, instr(field_value,'"'),instr(field_val...

Mysql - Insert queries inserting funny characters

Hi guys - I have a simple script which inserts values from a text file into a mysqldatabase - however some accented characters aren't inserted properly. Like lets say I have a word: Reykjavík I try to insert it using a simple insert sql statement and instead I this value ends up in the database???? Reykjavík How do I fix this? ====...

sql unique and setting constraints on inserts

I have a database where I need to avoid inserting duplicates. The requirements are: For the subset of rows with matching column 1, there can not be any that have the same column 2. For the subset of rows with matching column 1, there can not be any that have the same column 3 and 4. I'm new to SQL so is there a way of setting these re...

Help with MySQL SUM()

Here is my select query: SELECT SUM(rating) AS this_week FROM table_name WHERE UNIX_TIMESTAMP(created_at) >= UNIX_TIMESTAMP() - 604800) Which basically counts the rating of an item for the last week (604800 is a number of seconds in 1 week). The problem is that when there are no rows in the table, the this_week will be returned as ...

Group by MySQL mess

I am really having a trouble figuring this one out. I have a table 'Comments': cmt_id (primary key, auto incr), thread_id, cmt_text And I have these records in it: cmt_id thread_id cmt_txt 5002 1251035762511 Alright, I second this. 5003 1251036148894 Yet another comment. 5001 1251035762511 I am starting a ...

How do I reserve disk space in MS SQL script?

I was asked to create an MS SQL script that will create a database and reserve a 50 MB free disk space? How can I do that and what are the commands to use? Thanks. ...

Is it inefficient that linq to sql translates this query into the format: "select *"?

I'm not super familiar with Linq to SQL yet but something that strikes me is that this: var articles = (from a in DB.Articles where a.ArticleId == ArticleId.Question && a.DeletedAt == null && a.Votes >= minVotes orderby a.UpdatedAt descending select a). Take(maxarticles); gets translated to this: string query = "...

Writing desktop app that uses database. Suggestions for how to manage user access to tables?

I'm writing a depsktop application (in Java) that interacts with a database which stores mostly requirements documents,but I have a bit of a dilemma. Specifically, a problem with managing user access. To illustrate, I store all details on the folder structures in a single table. However, I would like to institute a user-group mechanism...

How can I sync a filesystem structure to SQL?

I currently have a filesystem path I would like to index into a SQL database. I need to access the data so that I can do queries against files based on modified times, or partial names, or many other items. Is there a way to somehow sync a filesystem to a database automatically, or even access a filesystem in a sql-like interface, wi...

ORDER BY on different columns in different directions in SQLite

I have a table defined by: CREATE TABLE bar_table ( _id INTEGER NOT NULL PRIMARY KEY, index INTEGER NOT NULL DEFAULT '65535', _date DATE ) My basic select statement is: SELECT * FROM bar_table ORDER BY <your-clause-here> How do I order my selection by index ascending, and date descending? i.e. small indexes come before lar...

Get table's primary key's name

Hello! I was wondering how can I list the user tables name with its primary key name as the second column? I'm doing half the job but I doesn't know what more to do. select table_name from user_tables ORDER BY (table_name) ASC Does anyone knows how? Thank you ...

ora-00933:SQL command not properly ended

I have the following code: begin for i in 1..2 loop insert into dba_xy.despatch select desp_id_seq.nextval, dbms_random.string('U',5), trunc(dbms_random.value(0000,9999)), prod_id from dba_xy.product prod_name from dba_xy.product; end loop; end; When I run it, oracle gives me the following error messag...

MySQL need help.. how can I filter max(date)

i have a table assumed like this [table a] UID | UNAME ------------------ 001 | a 002 | b 003 | c [table b] UID | LOGS ---------------------- 001 | 2009/08/01 001 | 2009/08/03 003 | 2009/08/02 and i want to have a query like this UID | LASTLOG -------------------- 001 | 2009/08...

Changing the size of a column in SQL Server

Hi all, I'm trying to change the size of a column in sql server using: ALTER TABLE [dbo].[Address] ALTER COLUMN [Addr1] [nvarchar](80) NULL where the length of Addr1 was originally 40. It failed, raising this error: The object 'Address_e' is dependent on column 'Addr1'. ALTER TABLE ALTER COLUMN Addr1 failed because one or more objec...

How to find unused ID in a column?

Possible Duplicate: SQL query to find Missing sequence numbers I have a table which has a user Id column, The user could select which user ID to add in the table. I am wondering if there is a one sql code that could point me to the list of unused user id or even just the smallest unused ID? For example, I have the following IDs...

error ORA-06550 ORA-00933.

I have a sales table: Name Null? Type SALE_ID NOT NULL NUMBER(4) SALE_DATE DATE NO_OF_PRODS NUMBER(4) PROD_ID NOT NULL NUMBER(4) CUST_ID NOT NULL NUMBER(4) DESP_ID NOT NULL NUMBER(4) SALE_RECEIPT NOT NULL NUMBER(5) I am trying to inser...

SQL Server SELECT Performance with JOINS

Hi, in SQL Server, I would like to know if there is any performance difference between doing this (A)... SELECT a.field1, a.field2, a.field3, b.field1 FROM table1 a INNER JOIN table2 b ON a.IDfield = b.IDfield and this (B)... SELECT a.field1, a.field2, a.field3, b.field1 FROM table1 a, table2 b WHERE a.IDfield = b.IDfield Well, thi...

Mixing MDX Drillthrough statement and SQL joins

I want to use an MDX drill through command but i also want to join it to some SQL tables as well. that is there will be an Id in the fact table and not a lot of other data I want to join this on to another table or view and produce a report based on those ID's returned in the drill down. Ideas? ...

Storing Date Only in sql server 2005

How to avoid the time portion of the datetime in sql server. I wants only the date portion to insert my database. Thanks in Advance ...

Postgres: regex and nested queries something like Unix pipes

Command should do: Give 1 as output if the pattern "*@he.com" is on the row excluding the headings: user_id | username | email | passhash_md5 | logged_in | has_been_sent_a_moderator_message | was_last_checked_by_moderator_at_time | a_moderator ---------+----------+-----------+----------------------------------...