sql

JOIN or Correlated subquery with exists clause, which one is better

select * from ContactInformation c where exists (select * from Department d where d.Id = c.DepartmentId ) select * from ContactInformation c inner join Department d on c.DepartmentId = d.Id Both the queries give out the same output, which is good in performance wise join or correlated sub query with exists clause, which one is ...

Extracting yyyy/MM/dd formated date from datetime datatype in T-SQL

I have my date values in postdate column in articles table in sql database table. It stores all date as well as time. I would like to get the date part only. i.e from 2010/07/01 12:45:12 i would likfe to get 2010/07/01 in my view ...

is it a good idea to write a stored procedure for storing an XML in SQL?

i want to write a stored procedure in java for SQL to parse and store the xml automatically in the corresponding tables is it a good idea or any one guide me how to do it. thanx in advance ...

How to get this result with and only with SQL ?

The question is: Two tables (t1, t2) Table t1: SELLER | NON_SELLER A B A C A D B A B C B D C A C B C D D A D B D C Table t2: SELLER | COUPON | BAL A 9 100 B 9 200 C 9 300 D 9 400 A ...

Run script on multiple DBs(SQL Server)?

Hello, lets say I have some update script: update sometable set somecolumn = 'somevalue' where xyz = 0 Now lets say I have multiple databases, like DB1, DB2, DB3 and so on. How coul I run this script on all of them without doing it manually? Thanks :) ...

SQL to get rows where a date time is 5 or less days away

I tried this and it returned incorrect rows SELECT `product_id`, `expiry` FROM `products_featured` WHERE `notified_expiry` = FALSE AND `expiry` != AND DATE_ADD(NOW(), INTERVAL 5 DAY) >= `expiry` I want to select all rows where the expiry date is within 5 days from now. The rows returned were [0]=> array(2) { [...

Timing compare in SQL Server 2008

Hi All. How to compare Indian time with world's other country times in SQL Server 2008? Means i want to know if in India its mid night 1 am what will be timing in other countries through SQL Server 2008 ...

Select records with order of IN clause

I have SELECT * FROM Table1 WHERE Col1 IN(4,2,6) I want to select and return the records with the specified order which i indicate in the IN clause (first display record with Col1=4, Col1=2, ...) I can use SELECT * FROM Table1 WHERE Col1 = 4 UNION ALL SELECT * FROM Table1 WHERE Col1 = 6 , ..... but I don't want to use that, cause ...

what's more efficient, SQL or flat file access?

Hi everyone, I am looking at upgrading a realtime program ASP.NET C#, that takes very frequently updated data and moves it from one database to another. Currently using a middle man app, that pulls from one and inserts into another using SqlBulkCopy. Is it better to have the source db server write a flat file and the middle man coll...

Tips on becoming an SQL guru

While writing an application of mine, I realized I was being silly by querying the database several times in some functions. I know I can just pack everything into a single query, and wind up with this nice dict of all the information that function needs. So I set out to accomplish this in a function where a user can share his uploaded f...

Insert-Select: reading data from other table when 2 Attributes r not the same (performance)

Hey there I’ve got a table like this: Create Table PersonAgent ( PersonID varchar2(10) not null, AgentID varchar2(10) not null, Address varchar2(50), City varchar2(50), Country varchar2(50) ) Well I need to generate this table new, coze some data are incorrect. If PersonID and AgentID are th...

mysql order and groupby

Hi everyone! I got a MySQL table of logs. It has the following fields: id, status_id, object_id, created, modified. I'm wondering what's the best way to get the latest status for each object? Thanks in advance! Edit: My last solution was to do SELECT id, status_id, object_id, created, modified FROM (SELECT * FROM logs ORDER BY creat...

How can I get all the information about a table in Oracle?

How can I get all the information about a table, its columns and constraints etc in Oracle? I am using desc MY_TABLE but that's only giving me column name, nullness and type. ...

how do i search an address form a group of columns from a table (zip,state,country)?

scenarioi:- 1) User enters an address into a search field. Address maybe zip,state or country 2) Now i have to take that address which may be in any order or which may just contain the country, state or zip and check the database if the the results exists or not. Any advice on this topic would be awesome ...

MS SQL SERVER: sql queries compared to general programming

i'm just starting out with ms sql server (2008 express) and spent the last hour or so trying out some basic queries. how does sql scripting (correct term?) compare to general computer programming? is writing sql queries as involved, lengthy to learn, needs as much practice, etc. as software development? is writing advanced sql queries co...

Is it possible?

Hi We are thinking of moving some of the 'hard coded' settings out of our windows forms application and storing them in the sql database in a table called App_Settings. The reason for this is we have values currently hard coded into appsettings and app.config which can change over time, and it is much easier and faster to update the val...

Help with SQL query

Short database schema: users (id) games (current_player_id) // has many cards cards (author_id, game_id, content, created_at) game_views(game_id, user_id) //shows which games user have seen I need to find game for user, which meets all whose rules: game's current_player is NULL (the game do not played by anybody right now) author o...

Get Column names with Delphi (Dbexpress)

Hi , I'm using this sql command to get column names : select COLUMN_NAME from INFORMATION_SCHEMA.COLUMNS where TABLE_NAME = 'MyTableName' but i don't know how can i using the executed SQL command results ! for example , this way doesn't work to extract the column names as a string value and i got this error = Operation Not Supporte...

SQL column/row format question

Hello, my query returns a column that can hold types of real estate. Values can be condo or duplex or house and so on. Instead of displaying condo, I just want a C in the column. My plan was to use a huge case/when structure to cover all the cases, is there an easier way? Just displaying the first letter in upper case wont work by the wa...

PostgreSQL recursive with.

Hi, I need help with a recursive query. Assuming the following table: CREATE TEMPORARY TABLE tree ( id integer PRIMARY KEY, parent_id integer NOT NULL, name varchar(50) ); INSERT INTO tree (id, parent_id, name) VALUES (3, 0, 'Peter'), (2,0, 'Thomas'), (5,2, 'David'), (1, 0, 'Rob'), (8, 0, 'Brian'); I can ...