sql

How to configure reference to be deleted on parent table update?

I have two tables: info: ID, fee_id and fee: ID, amount and a reference between them (SQL Server 2008): ALTER TABLE info WITH CHECK ADD CONSTRAINT FK_info_fee FOREIGN KEY(fee_id) REFERENCES fee (ID) ALTER TABLE info CHECK CONSTRAINT FK_info_fee GO How to configure this reference that way so a record in fee will be deleted if inf...

SQLParameter not working properly

I am trying to access a stored procedure and I'm getting an error that says: Procedure or function 'getbug' expects parameter '@bugID', which was not supplied. This is my code to call the procedure. SqlCommand cmd = new SqlCommand("getbug", cn); cmd.Parameters.Add(new SqlParameter("bugID", bugID)); bugID is set as 1089 (and is t...

Join Query returns empty result, unexpected result

Hello all, Can anyone explain why this query returns an empty result. SELECT * FROM (`bookmarks`) JOIN `tags` ON `tags`.`bookmark_id` = `bookmarks`.`id` WHERE `tag` = 'clean' AND `tag` = 'simple' In my bookmarks table, I have a bookmark with an id of 70 and in my tags table i have two tags 'clean' and 'simple' both that have the colu...

sql server procedure optimization

SQl Server 2005: Option: 1 CREATE TABLE #test (customerid, orderdate, field1 INT, field2 INT, field3 INT) CREATE UNIQUE CLUSTERED INDEX Idx1 ON #test(customerid) CREATE INDEX Idx2 ON #test(field1 DESC) CREATE INDEX Idx3 ON #test(field2 DESC) CREATE INDEX Idx4 ON #test(field3 DESC) INSERT INTO #test ...

Separate Query for Count

Hello, I am trying to get my query to grab multiple rows while returning the maximum count of that query. My query: SELECT *, COUNT(*) as Max FROM tableA LIMIT 0 , 30 However, it is only outputting 1 record. I would like to return multiple record as it was the following query: SELECT * FROM tableA LIMIT 0 , 30 Do I have to use s...

Storing info in a PostgreSQl database issue

Ok I am making a registry for my website. First page asks for some personal info if($error==false) { $query = pg_query("INSERT INTO chatterlogins(firstName, lastName, gender, password, ageMonth, ageDay, ageYear, email, createDate) VALUES('$firstNameSignup', '$lastNameSignup', '$genderSignup', md5('$passwordSignup'), $m...

SQL Get Top 10 bug records by count but with ID

I asked a question earlier today here. However, what I neglected to check with that question is how can I get AN id of those bug records? So for example, if I have a bug that has happened 3 times, how can I return one of the ID's from those 3 records? ...

how can join a query result set with an existing table?

is there any way to avoid using tmp table? I am using a query with aggregate function (sum) to generate the sum of each product: the result looks like this: product_name | sum(qty) product_1 | 100 product_2 | 200 product_5 | 300 now i want to join the above result to another table called products. so that i will have ...

Which Database to choose?

I have the following criteria Database should be protected with a username and password. It should not be possible to copy the database file and use it else were like MS Access. There will be no central database server. Each machine will run their own database server locally and user will initiate synchronization. Concept is inspired f...

Search a string to find which records in table are inside said string

Hello, Say I have a string. Then I have a number of unique tokens or keywords, potentially a large number in a database. I want to search and find out which of these database strings are inside the string I provide (and get the IDs of them). Is there a way of using a query to search the provided string or must it be taken to applicat...

MySQL GROUP_CONCAT + IN() = missing data :-(

Example: Table: box boxID color 01 red 02 blue 03 green Table: boxHas boxID has 01 apple 01 pear 01 grapes 01 banana 02 lime 02 apple 02 pear 03 chihuahua 03 nachos 03 baby crocodile I want to query on the contents of each box, and return a table with each ID, colo...

Mulitple full joins in Postgres is slow

I have a program to use the IMDB database and am having very slow performance on my query. It appears that it doesn't use my where condition until after it materializes everything. I looked around for hints to use but nothing seems to work. Here is my query: SELECT * FROM name as n1 FULL JOIN aka_name ON n1.id = aka_name.person_i...

MySQL - How do I inner join sorting the joined data

I'm trying to write a report which will join a person, their work, and their hourly wage at the time of work. I cannot seem to figure out the best way to join the person's cost when the date is less than the date of the work. Let's say a person cost $30 per hour at the start of the year then got a $10 raise o Feb 5 and another on Mar 1....

Please tell me what is error in my date comparison sql query

Please help me to find out error in my SQL query. I have created this query to compare dates select * from Joinplans jp where cast(convert(varchar,GETDATE(),103) AS datetime) BETWEEN CASE(convert(varchar,jp.planstartDate,103) AS datetime) AND CASE(convert(varchar,DATEADD(DAY,jp.planDays,jp.planstartDate),103) AS DATETIME) ...

Continuation - Viewing FIRST_ROWS before query completes.

I have identified the query constructs my users normally use. Would it make sense for me to create composite indexes to support those constructs and provide FIRST_ROWS capability? If I migrate from SE to IDS, I will lose the ability to write low-level functions with C-ISAM calls, but gain FIRST_ROWS along with other goodies like: SET-RE...

batch update mysql table

I have a table with a column called time, "HH:MM:SS". How can I do a batch update so that the value increment by 1 hour? Is it something like: update <table_name> set <time_column> = <time_column> + 3600 where ... ...

MySQL count statements error - operand should contain 1 column(s)

I am trying to do multiple counts everyone was working accept the first sub select (list1) I get an error that reads "Operand should contain 1 column(s)" i'm guessing it has something to do with the AND, but i'm not sure how I would fix this one. Select Count(list0.ustatus) AS finished_count , (Select list1.ustatus, Count(*) ...

sql create view in one to many relation

I want to create a view in a one-to-many relation. Here are my relations: (a -* b) (a -* c) I want to create a view to have this data: a1 - (all b's related to a1 + all c's related to a1) I don't want something like (a1,b1,c1 - a1,b1,c2 ,...). I want data to be: (ID,DESCRIPTION1,DESCRIPTION2,DESCRIPTION3) in one record. For exa...

mysql result set joining existing table

is there any way to avoid using tmp table? I am using a query with aggregate function (sum) to generate the sum of each product: the result looks like this: product_name | sum(qty) product_1 | 100 product_2 | 200 product_5 | 300 now i want to join the above result to another table called products. so that i will have a s...

SQL: Join vs. subquery

I am an old-school MySQL user and always preferred JOIN over sub-query. But nowadays everyone uses sub-query and I hate it, dunno why. Though I've lack of theoretical knowledge to judge myself if there are any difference. Well, I am curious if sub-query as good as join and there is no thing to worry about? ...