SQL query: for each element, add multiple values

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 |

hasManyThrough does not work

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

sql server float stuff

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

Case report in JOIN

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

SQL Alternative to Using WHERE as a Subquery

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

sql: gets the group 'n' consecutive lines (could be in between)

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

Insert multiple lines in SQL

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

how to secure a valuable stored procedure in the sql server

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

Pass the time interval via a variable in Oracle SQL

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

How to join a single line in the table attached with postgres?

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

How to get the last entry of the particular identifier

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

How to use SQL parameters to obtain the dataset from SQL Server

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[

SQL: Select from one table matching criteria in another?

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

Creating a general SQL query builder

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 and write MP3s in the database

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

How to optimize this SQL selection query?

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(

Where can I learn the SQL method to extract data

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

How is the database migration performed?

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)

Keep synchronized tables in Oracle

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