I have created a SQLfiddle demo with sample data and desired result here :(http://sqlfiddle.com/#!9/dfe73a/7) sample data -- table company +--------+---------+ | id | name | +--------+---------+ | 1 | foo | | 2 | bar | +--------+---------+ -- table s
i need to write a query that joins a lot of queries. They are connected by an ID. The problem is that in one of the queries, the value I have to select is a "single-group group function" and i must evaluate a condition on the ON clause that must
I have an interesting use case. Basically I have a sourceUser: UserRow and targetUser: UserRow that I need to merge. The merge means marking sourceUser as inactive and copying over all source linked accounts (detail) to the target user. All the missi
How to write a SQl query to create "NewTable" using Table1 and Table2 which the result look like "NewTable" below ? Table1 EmmployeeID | 1 | | 2 | | 3 | Table2 AgencyID | a | | b | | c | NewTable |EmmployeeID|AgencyID| | 1 | a | | 1 |
I have this table, categories: id | name | slug Products: id | name | slug | category_id | brand_id Brands: id | name | slug | The problem occurs when I try to bring Brands here in the category of feature. Category Model public function brands() { re
I have a problem with a stuff query grondstof = stuff(( select '[' + cast(cast((Grondstof1) as int) as varchar(20)) + ']' FROM table g FOR XML PATH(''), TYPE).value('.', 'NVARCHAR(MAX)'), 1,0, '') this is what get [0][0] and what i expect [0.40][0.20
Are there any drawbacks to storing addition data in my join/junction table. For example, I am working on a database of trucking companies and I have 3 tables: Table 1 - company, Table 2 - trailer_type, Table 3 - junction_table, Each company can have
This is my query INSERT INTO Tbl_DomainWiseStats (subdomainid, tendercount, Type_cat, DisplayText) SELECT ' + CAST(@domain_id AS VARCHAR(100)) + ' , TenderCount , ''ByCountry'' ,Country FROM (SELECT DISTINCT V.Country, COUNT(DISTINCT Sr_No) as Tender
I have this query: Select b.building_pk, bil.building_fk, bil.BillingAccountStatus_fk, b.ACTL_TNT_CT From [DB].[Schema].Building b (nolock) left Join [DB].[Schema].Billing bil (nolock) on bil.building_fk = b.building_pk join ##GlobalTempTable1 tt (no
I'm learning SQL using PostgreSQL, and I'm trying to modify one of the queries from the PostgreSQL Tutorial website. The original query is this: SELECT film_id, title FROM film WHERE film_id IN ( SELECT inventory.film_id FROM rental INNER JOIN invent
Below is my theater table: create table theater ( srno integer, seatno integer, available boolean ); insert into theater values (1, 100,true), (2, 200,true), (3, 300,true), (4, 400,false), (5, 500,true), (6, 600,true), (7, 700,true), (8, 800,true); I
I have requirement as, In target file date is like 20151125 needs to convert it to 11/25/2015 through informatica. Files are generating from informatica to unix server. I tried with SELECT to_char(to_date(substr(IN_DATE,16,20),'YYYY/MM/DD HH24:MI:SS'
In Oracle Application Express. I created a table named Employees. I want to insert multiple rows values by a single command . I used this command INSERT INTO Employees VALUES( (100,'Steven','King','SKING','515.123.4567',TO_DATE('06-17-1987','MM- DD-Y
This question might not be perfect for this platform but I trust people here a lot. I am coding a data transfer application for an ERP system, many people create C# projects that are slow, not flexible and full of errors. I found a way to do it in SQ
I have a table of around 60 columns and 400,000 rows and increasing. Our company laptops and MS Excel cannot handle this much data in RAM. So I decided to store the data in MS Access and link it to Excel. However the pivot in Excel still downloads al
This query returns the value based on given interval time 10. SELECT TO_CHAR((TO_DATE('23:20:20','HH24:MI:SS') - INTERVAL '10' MINUTE), 'HH24:MI:SS') FROM DUAL; Output: 23:10:20 I want to pass this minute interval via variable using below code: decla
I have the following schema: CREATE TABLE author ( id integer , name varchar(255) ); CREATE TABLE book ( id integer , author_id integer , title varchar(255) , rating integer ); And I want each author with its last book: SELECT book.id, author.id, aut
Below is my query I want to fetch last entry of visitno ,of particular pid,this query works fine but selects all rows of pid ,visistNo is of Number Datatype public int GetPatientID_visitNo(int pid) { int data = 0; try { string sql = "Select VisitNo F
I'm working on C# project and I'm new to this technology. I want to read some data from SQL Server 2008, and I write the following code public User select(string username, string password) { string connection = ConfigurationManager.ConnectionStrings[
Ok I have searched SO and Google but haven't really found a definitive answer so throwing it out there for the SO community. Basically I have a table of longitudes and latitudes for specific points of interest, the sql query will know which location
I'm trying to create and XML feed with the result set of a SQL query. One of the fields contains ' characters which is causing an error in the resulting XML file. How do I replace the ' character. I've read posts that suggest something like Replace(m
I'd really appreciate some help with an SQL query across tables. I realise this sort of thing is asked constantly, but I can't find a similar enough question to make sense of the answers. I want to select rows from table_A that have a corresponding t
I'm trying to run the following code but get a casting error. How can I rewrite my code to achive the same ? boolResult= (bool?)dataReader["BOOL_FLAG"] ?? true; intResult= (int?)dataReader["INT_VALUE"] ?? 0; ThanksUse the "IsDbNul
what would be the best way to create a Query builder in delphi? I have devexpress quantum grid, so I can display data easily.At least as of a few years ago, best query building component for Delphi was "Simple Query", an inexpensive component fr
how to read MP3 from Sql database. in sql i have stored the file as binary format. now i want to retrive the Mp3 file stored in the sql and show in my aspx page. how???? pls help...In its simplest form this is how you would get the raw bytes, can't r
I need to create trigger in SQL Server 2008 that gone insert all values from one row in which some value was changed into Log table! For example if i have table Employees that have column id, name , password, and i update this table and insert new va
I am able to complete this query but it takes 25 seconds. That's too long! How can I optimize this query? SELECT COUNT(DISTINCT u1.User_ID ) AS total FROM UserClicks u1 INNER JOIN (SELECT DISTINCT User_ID FROM UserClicks WHERE (Date BETWEEN DATE_SUB(
There's a gap in my SQL knowledge I'd like to fill and I'm after recommendations on where to find resources, eg. websites, how-tos, books, etc. I've been using SQL databases for a long time. I'm quite comfortable with: basic SQL and its syntax; creat
i remember in my previous job, i needed to do data migration. in that case, i needed to migrate to a new system, i was to develop, so it has a different table schema. i think 1st, i should know: in general, how is data migrated (with the same schema)
We're about to run side-by-side testing to compare a legacy system with a new shiny version. We have an Oracle database table, A, that stores data for the legacy system, and an equivalent table, B, that stores data for the new system, so for the dura