sql

Adding "comments" table with an sql connection and php calling

hey.. i need to place a "comments, faq, contact us" table on my site where users will place their name and the comment they want to say to the admin of the site.. some reports about a game they've played.. the "comments" then it will be saved inside an mysql database ("games") within the given "name" and the "ipaddress" of the user (comi...

What do you consider to be the best balance of columns within an address table?

Almost every time that I build an application, I find myself creating an 'address' table to contain addresses for the system. What columns do you create within your 'address' table (or tables if you normalize addresses over more than one) and what is your reasoning behind it? ...

how to join two table different database?

in have database 1. test 2. test2 database test table1 field [ id ,password ,name , lastname ] database test2 table2 field [ id] how to select test and test2 where table1 have id in test2.table2.id in c# with sql server 2005 ...

How to catch "Cannot delete or update a parent row: a foreign key constraint fails" expression and throw it on to a new page ?

I use the following code to catch the SQL Expression, when i try to delete a primary key wich is also a foreign key and is mapped to another table, my question is, how do you forward this to a common error page ? To catch the expression, if(e.Exception is SqlException) { SqlException ex = (SqlException)e.Exception;...

Are there any performance issues if an sql query contains lot of joins?

Are there any performance issues if an sql query contains lot of joins? ...

Storing dependent dates in SQL

I have quite a few situations where I have database structures similar to: TABLE Event (EventID INT PrimaryKey, Start DATETIME, Finish DATETIME); and TABLE EventTask (EventTaskID INT PrimaryKey, EventID INT ForeignKey, TaskStart DATETIME, TaskFinish DATETIME) 1 to many relationship between Events and EventTasks, etc. When the dates i...

How to intercept and modify SQL query in Linq to SQL

Hi, I was wondering if there is any way to intercept and modify the sql generated from linq to Sql before the query is sent off? Basically, we have a record security layer, that given a query like 'select * from records' it will modify the query to be something like 'select * from records WHERE [somesecurityfilter]' I am trying to fi...

Finding missing number between tables in SQL

Hello members, I'm working on the following 2 tables on Oracle 10g. I'm attempting a rather simple task, but can't get my query right, perhaps due to my lack of understanding of the basics. I want to query out the account_no from TEMP which is not present in BMF. Two Tables: Table 1: BMF: 1372 rows account_no | trans_amount | tra...

Ordering table in join : SQL Tuning

I having a query with 10 tables joined. Do i need to follow any order in writing the sql joins? Suppose if table-1 has 1000 records, table-2 has 900 records and so on So do i need to write the join for the table has higher number of records and followed by lower number of records? so that we improve the performance of sql. ...

Oracle Date format - Strange behaviour

I am writing a SQL query to retrive data from a table between two dates. I give two inputs as shown. I convert the Date TO_CHAR(DD/MON/YYYY). 1. StartDate > 01/SEP/2009 EndDate < 01/OCT/2009 2. StartDate > 01/SEP/2009 EndDate < 1/OCT/2009 I dont get any result for the first input. When I change it to second one i get the r...

When creating a view in MySQL, can update commands be run on that view?

I am creating a HUGE query with 5 or 6 join, and want to turn this into a view. But, I need too be able to update this view. Is this possible? By update, I mean, run an SQL UPDATE command, alter a value, and then let the changed values filter through to the appropriate tables. ...

What's the difference between "select max" and "select.. where column=max"?

I have two queries: SELECT id, max(index) from table; and SELECT id, index from table where index=(select max(index) from table); Is there any difference between the two? I ran the code in MySQL Query Browser and found that the results are the same. But I just feel that there should be a difference. If there is a diff, mind to at...

SQL Get char at position in field

How can I get the character at position 4 in a field? e.g. field contents = "hello" I want to return the value of position 2 = "l" ...

Error when replacing words that contain quotes in mySQL

I have updated many records already, but when it came to a word that contains a quote I get this error: "ERROR: Unclosed quote @ 1357" I know why it's giving me this error, I just don't how to solve it. Here's a sample: UPDATE invnum SET cAccountName = replace(cAccountName,'JOHN'S','BEN') Thanks in advance. ...

How to select first 'N' records from a database containing million records?

I have an oracle database populated with million records. I am trying to write a SQL query that returns the first 'N" sorted records ( say 100 records) from the database based on certain condition. SELECT * FROM myTable Where SIZE > 2000 ORDER BY NAME DESC Then programmatically select first N records. The problem with this approac...

Referring to results of a sub query in main query

Hi, I have a sub query that returns one column, showing as GroupType, I then want to do a CASE function on this result within the main query, however I get an invalid column name when using the CASE statement. Can i do this in SQL to do I have to refer to it by a different name ...

SQL: find percentiles

I have a table that has a certain numeric column called Score. I would like to execute a query on that table, whose result will have 100 rows, each representing the score corresponding with that percentile. For example, a result may look as follows: Percentile | Score --------------------- 01 | 10 02 | 12 03 ...

DB2 SQL add rows based on other rows.

Hi All, I have a select statement that I want to use as the basis for adding more rows to a table. The new rows will have some columns modified and the original row will have to be altered also. This is a once off occurance and the DB can be taken offline if that helps. Any ideas? Thanks, Joe ================= Description Update M...

TSQL / SP INSERT statement with text & values

HI, I have an insert statement in a Stored Procedure that requires the value data to be a combination of text and variables/inputs. However my SQL Manager is giving an error on this 'camp' value when trying to compile it. Here is the statement as it currently exists; BEGIN TRAN INSERT INTO TBL_DONATIONS ([donations_MemberID], [d...

SQL conditional GROUP BY: how to do it?

Let's say I have the following SQL query: SELECT Meeting.id AS meetingId, Bill.id AS billId FROM Meeting LEFT JOIN Bill ON Meeting.FK_BillId = Bill.id That outputs the following: meetingId | billId ------------------ a | NULL b | NULL c | 1 d | 1 e | 1 f | 2 g ...