sql

Searching for newlines in a Oracle DB using SQL 'like' clause

I'm trying to see if a particular column in a table in my Oracle database has any strings which contain a newline character, so a wildcard, a newline, and another wildcard. I've tried the like command and a combination with CHR(10) and tried escaping the newline itself, but to no avail. What would be the proper way to detect a newline ...

Purpose of splitting a select query into chunks?

Edit: the example was bad, caused answers unrelated to the question. Given a large select query, in a simple program like: Statement stmt = con.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_READ_ONLY); ResultSet srs = stmt.executeQuery( "SELECT AGE FROM USERS"); while (srs...

sql find duplicate entry and insert into new column

I have a table with columns: Date, Phone, Name, and Event I need a query that will first recognize the duplicate phone entry, and then assign the name of whichever one has the earlier date to the event column. ...

SQL Server 2005 Index rebuild when increasing the size of a varchar field

I have a 12 varchar(50) fields in a table of about 90 million rows that I need to increase to varchar(100) in length. Each of these fields has an index (with only the one field as a member). If I increase the length of the varchar fields, will the indexes either need to be rebuilt (or would be rebuilt automatically), or would the stati...

SQL DateTime Datediff

Trying to return the Date stored in the Database in the form Days: Hours : Minutes But the SQL Code below does not seem to work well. select CONVERT(VARCHAR(40),DATEDIFF(minute, MAX(sends), GETDATE())/(24*60)) + '<b>days:</b> ' + CONVERT(VARCHAR(40), DATEDIFF(minute, MAX(sends), GETDATE())%(24*60)/60) + ' <b>hours:</b> ' + C...

how to solve parameter in sp_executesql

Hi, I have the following query: create proc [dbo].GetCustById as DECLARE @sql nvarchar(500) DECLARE @Param nvarchar(200) SET @sql = 'select @columnName from customer where custId = @custId' SET @Param = N'@columnName varchar(10), @custId int' EXEC sp_executesql @sql, @Param , @columnName = 'Address1', @custId = '42' But it always r...

Best free database management system for beginners (with capability for 20gb DB)

Hi, I'm trying to "open" (?) a 20gb database with a .sql extension and can't find any documentation for beginners that doesn't already assume database access. I think as a first step I need some database management system. It don't need to have any development type capabilities - just the ability to compile (right word?) SQL. Any sug...

sql (oracle) to select the first 10 records, then the next 10, and so on

I figure I might just be missing some obvious syntax but what is the sql (oracle) to select the first 10 records, then the next 10, and so on? I tried using rownum but can seem to get rownum > X and rownum < Y to work. llcf ...

MySQL joins for friend feed

Hi everyone, I'm currently logging all actions of users and want to display their actions for the people following them to see - kind of like Facebook does it for friends. I'm logging all these actions in a table with the following structure: id - PK userid - id of the user whose action gets logged actiondate - when the action happe...

Updating users table from complex SQL query, users.id not recognised?

So the other day, I asked this question about how to combine three complex queries and found a way to do it. Now I'm trying to use those queries to update a field in the users table and can't find a way to make it work. Here's the query: update users set field_sum =( select sum(field_sum) from ( select sum(field_one) as fi...

MySQL greatest-n-per-group trouble

Hey everyone. I believe this is a 'greatest-n-per-group' question but even after looking at several questions on StackOverflow, I'm unsure how to apply this to my situation... I'm using a MySQL database and have a basic blog-type system set up about Computer Applications... The tables look like this: POSTS post_id post_created post_t...

Generate range of constants in SQL Server

Is there a way to select a range of constants, such as every integer between 1 and 100, or every month between two dates? Instead of doing this... select '2010-01-01' union select '2010-02-01' union select '2010-03-01' union select '2010-04-01' union select '2010-05-01' union select '2010-06-01' union select '2010-07-01' union select '...

mysql short union

I'm far from being a mysql guru, so need to know if there's a way to make this query faster,shorter and more compact. (SELECT DISTINCT(cfrm.nid), f.filename, n.title, n.created FROM content_field_raamatu_marksonad cfrm LEFT JOIN node n ON (n.nid = cfrm.nid) LEFT JOIN content_field_kaanepilt cfk ON (cfk.nid = n.nid) LEFT JOIN ...

How can I create foreign keys for junction table

I have Object1 and junction table and Object2. Object2 is table that has many junction tables, but can have only one junction table torefrencing to it. When table Object1 is removed, then junction table and Object2 should be removed. How can I make foreign keys in this situation? But when Object2 is removed, then only junction table shou...

exception while adding multiple rows to datatable. Couldn't store <System.Data.DataRowCollection>

idLocals is Primary key in database Populating the datatable oDtLocalCharge = bll.GetData(); i am copying the datatable in another function dtLocalCharges = oDtLocalCharge.Copy(); and trying to add rows using below code DataRowCollection drr = oDtLocalCharge.Rows; dtLocalCharges.Rows.Add(drr); When i try to add rows to dat...

SQL queries with views and subqueries

select nid, avg, std from sView1 where sid = 4891 and nid in (select distinct nid from tblref where rid = 799) and oidin (select distinct oid from tblref where rid = 799) and anscount > 3 This is a query I'm currently trying to run. And running it like this takes about 3-4 seconds. However, if I replace the "4891" value w...

Which language was first to introduce the "in" keyword first: SQL or Object Pascal?

(Or possibly another language?) I know both SQL and Object Pascal first appeared in 1986, but I'm not sure which one had the in keyword first, so anyone who can point me to a definitive source will get my thanks and some reputation. Yes I searched for the answer, but I think my Google-fu is weak. :( ...

Django complex filtering of related objects

Hello, I've faced with following issue, basically I do it like this: class Account(models.Model): TraffPerMonth = models.IntegerField(default=0) Tariff = models.ForeignKey('Tariff') class Tariff(models.Model): InetTraff = models.IntegerField(default='0') and here is the select: for user in Account.objects.all(): t_traf...

Tuning table select SQL having a RAW column in Oracle 10g

Hi all, I have a table with several columns and a unique RAW column. I created an unique index on the RAW column. My query selects all columns from the table (6 million rows). when i see the cost of the query its too high (51K). and its still using INDEX FULL scan. The query do not have any filter conditions, its a plain select * from...

Problem with active-record and sql

Hi everybody, I have a little problem: I can't compose sql-query inside AR. So, I have Project and Task models, Project has_many Tasks. Task has aasm-field (i.e. "status"; but it doesn't matter, i can be simple int or string field). So, I want on my projects index page list all (last) projects and for every project I want count it's ac...