sql

what is correct sql statement syntax in PHP?

Hi, when I write a sql statement in php, i usualy write it as below SELECT COUNT(*) FROM catalogsearch_query AS main_table but I found that some people write sql statement like SELECT COUNT(*) FROM `catalogsearch_query` AS `main_table` do I have to use ` ? ...

Non-Access or -base QBE tool?

I'm currently looking for a QBE tool that can execute queries on PostgreSQL or MySQL. OS doesn't really matter. Reason is that we've got to do QBE at school but I don't want to use neither Microsoft Access nor OpenOffice.org Base (lack of features). Any help would be appreciated. ...

Delete all records with EDM

Yes, I need to clean a table and I have EDM that comes with .net 3.5 sp1 (I haven't tried with EF4). I know that works: foreach(var item in ctx.Elements){ ctx.DeleteObject(item); } but it's not a point to get all data from the table and and deleting one by one. Ok, I know it's deleted when I run ctx.SaveChanges(); but DELETE FROM [...

How to troubleshoot ORA-02049 and lock problems in general with Oracle

I am getting ORA-02049 occasionally for some long-running and/or intensive transactions. There is seemingly no pattern to this, but it happens on a simple INSERT. I have no clue how to get any sort of information out or Oracle, but there has to be a way? A log over locking or atleast a way to see current locks? ...

MySQL, if a value is in one of two columns, return the value from the other one

Hi, This might be an easy one, but I'm not really experienced with sql. I have a table with two user_id columns, user1 and user2. This table contains some compared values between the two users. I want to send in an user id, and return all the id's from the other user when the sent user is either user1 or user2. I guess some sort of i...

SqlBackup from my client app

I have an client app that runs on several machines, and connects to a single SQL database. On the client app, the user has the possiblity to use a local SQL (CE) database or connect to a remote SQL database. There is also a box where a backup location can be set. For the backup of the remote SQL database I use the following code: var b...

Group / User based security. Table / SQL question

Hi, I'm setting up a group / user based security system. I have 4 tables as follows: user groups group_user_mappings acl where acl is the mapping between an item_id and either a group or a user. The way I've done the acl table, I have 3 columns of note (actually 4th one as an auto-id, but that is irrelevant) col 1 item_id (item...

What's the default of ONDELETE and ONUPDATE for foreign keys in SQL?

My guess would be that a foreign key reference is set to RESTRICT by default. But, is there any standard for this? Is the default equal on any database type? Or should these values be defined in all statements just to be sure? ...

How to structure this query...?

Hi Everyone... Consider the following table.... hotel facilities 1 internet 1 swimming pool 1 wi-fi 1 parking 2 swimming pool 2 sauna 2 parking 3 toilets 3 bungee-jumping 3 internet 4 parking 4 swimming pool I need to select only the hotels that have parking,...

Can Anyone explain why NULL is used in this query?

Also what will be the scenarios where this query is used select * from TableA where exists (select null from TableB where TableB.Col1=TableA.Col1) ...

Grails: Help with HQL query.

I'm not very good in SQL and HQL... I have two domains: class Hotel { String name } class Room { Hotel hotel float price } How many hotels have at least one room ? ...

Integer comparison as string

Hi I have an integer column and I want to find numbers that start with specific digits. For example they do match if I look for '123': 1234567 123456 1234 They do not match: 23456 112345 0123445 Is the only way to handle the task by converting the Integers into Strings before doing string comparison? Also I am using Postgre rege...

Replace returned null values in LEFT OUTER JOIN

SELECT WO_BreakerRail.ID, indRailType.RailType, indRailType.RailCode, WO_BreakerRail.CreatedPieces, WO_BreakerRail.OutsideSource, WO_BreakerRail.Charged, WO_BreakerRail.Rejected, WO_BreakerRail.RejectedToCrop, WO_BreakerRail.Date FROM indRailType LEFT OUTER JOIN WO_BreakerRail ON indRailType.Rai...

Refactoring SQL

Are there any formal techniques for refactoring SQL similar to this list here that is for code? I am currently working on a massive query for a particular report and I'm sure there's plenty of scope for refactoring here which I'm just stumbling through myself bit by bit. ...

Advice Needed To Normalise Database

hey all, im trying to create a database for a feedback application in ASP.net i have the following database design. Username (PK) QuestionNo (PK) QuestionText FeedbackNo (PK) Username UserFeedbackNo (PK) FeedbackNo (FK) QuestionNo (FK) Answer Comment a user has a unique username a user can have multiple feedbacks i was wondering...

formatting the output of a sql query.

Hi! I am using solaris os. from solaris im logging into sql plus. my database is oracle 9i. i am spooling the output of my query into a file. i want in .csv format so that i can copy it into excel. can any1 help me out. my query is like. select name,id,location from employee; ...

Sql Distinct Count of resulting table with no conditionals

Hello everyone, I want to count the number of accounts from the resulting table generated from this code. This way, I know how many people liked blue at one time. Select Distinct PEOPLE.FullName, PEOPLE.FavColor From PEOPLE Where FavColor='Blue' Lets say this is a history accounting of what people said their favorite color when the...

Getting the sum of a datediff result

Hi I have a SQL statement (MS SQL Server 2005) that does a simple calculation of the differences in dates on a few records. I want to return the total/sum of the DATEDIFFs too. SELECT (DATEDIFF(day, StartDate, EndDate)+1) AS myTotal FROM myTable WHERE (Reason = '77000005471247') How do I get the SUM from myTotal? Tha...

Select All as default value for multiple values parameter SSRS

Hi there I'm building a report in VS08 with a lot of multiple values parameters and it's working great, but I would like to have have the "(Select all)" option as default value when the report is opened. Is there some kind of expression or sql code I can use to make this happen or do I need to choose "(Select all)" every time, in every ...

Temporary intermediate table

In our project to generate massive reports in oracle we use some permanent table to hold intermediate results. For example to generate one report we run few queries and populate the table, at the final step we join the intermediate table with huge application tables. These intermediate tables are cleared for next report run. We have few...