Questions tagged [derived-table]

A derived table is a term in SQL for a set of records that result from one query that can be used in another query. Derived tables are useful in simplifying complex queries into a series of simpler steps. They are often a simpler alternative to using temporary-tables.

A derived table is a term in SQL for a set of records that result from one query that can be used in another query. Derived tables are useful in simplifying complex queries into a series of simpler steps. They are often a simpler alternative to using temporary-tables.

188 questions
0
votes
1 answer

How to get employee name and id who have two phone numbers in second table

These are two tables 1. emp_table, 2. phone_table. How to get employee name and id who have two phone numbers in second table
raveendra
  • 13
  • 1
0
votes
1 answer

How to add join based on conditions in mysql

How to set joins based on conditions, I am trying to use if or case for doing this, how can I achieve this. mysql error Code: 1241. Operand should contain 1 column(s) SET @sUserId = 15; SELECT userClip.userId FROM ( select if(@sUserId > 0…
pitu
  • 822
  • 3
  • 11
  • 35
0
votes
1 answer

Place an Insert Statement into a Select Statement

I have read the other questions and all of the posted comments/answers to questions that are similar to this one. None of them seem to answer this question directly. I am wanting to know if there is a way to either concatenate or place an INSERT,…
Ashton
  • 363
  • 1
  • 4
  • 21
0
votes
1 answer

Have Entity Framework use Type property instead creating column per Derived Type

Say I have an abstract Person Table, and derived tables, Student and Teacher, Admin etc. Person has a enum property PersonType with values for each derived class, and a virtual collection Events. Now when Entity Framework creates the Events table,…
0
votes
1 answer

Teradata SQL Derived table data redistribution

This is once again a a question for SQL Pundits. I can create derived tables in Teradata using these approaches - With ( __,__) (select statement ) alias query -- select ____ from a , ( select statement ) b < Join condition ) I wondered in…
user1874594
  • 2,277
  • 1
  • 25
  • 49
0
votes
1 answer

SQL Server - Deriving A table

I have the following query which yields the following result. select RowNumber, ApplicationDecisionID, RowNumber-1 as previousDescIDRowNumber from ( select ROW_NUMBER() OVER(ORDER BY applicationdecisionid ASC) AS RowNumber, ApplicationDecisionID…
dstewart101
  • 1,084
  • 1
  • 16
  • 38
0
votes
1 answer

Convert working SELECT query into UPDATE query

In SSMS 2014 I have a working SELECT query and want to convert it to and UPDATE statement to update a field in the main table. I have tried and tried many solutions, each results in a different error. I've managed to do simple UPDATE SET WHERE…
Kev
  • 37
  • 1
  • 6
0
votes
2 answers

"Every derived table must have its own alias" in complex MySQL query

I have a more or less complex MySQL select query which is basically a select from a join of two complex tables: SELECT * FROM ( SELECT ProblemID , 10*POWER(COUNT(ProblemID), 2) AS TagsSignifikanz FROM (…
0
votes
2 answers

Why must every derived table have its own alias?

select a as average,name from (select avg(marks) as a,name from marks,student where rollno=roll group by marks.roll); ERROR 1248 (42000): Every derived table must have its own alias I know the correction. Just want to know why I have to…
0
votes
1 answer

SQL Server - Derived Table Data Storage

In SQL Server while writing a query, I noticed that the data in inner query which is a derived table when joined with another table is taking long. The keys joined to the outer table is on the primary key. So I was surprised since the data was about…
Lex
  • 19
  • 2
0
votes
1 answer

Oracle query stumped - derived table

It's been a long time since I've done more than the most basic sql queries. But I ran into this one today and have spent a few hours on it and am stuck with my derived table attempt (this is for an Oracle db). Looking for a few tips. Thx. TABLE:…
0
votes
1 answer

SQL how to count the number of credit cards that had at least 1,5,10,20 etc transactions

I have a data set of credit card transactions. create table trans ( card_id int, amount int ); insert into trans values (1, 1); insert into trans values (2, 1); insert into trans values (3, 1); insert into trans values (4, 1); insert into…
davidjhp
  • 7,816
  • 9
  • 36
  • 56
0
votes
1 answer

Using result set from an outer query in inner query in MySQL

I have two tables called "nodes" and "links". I am performing the following query and it returns the results I want. How to optimize this one? I am using the resultset of the outer query in inner query. How to reference to the resultset of the outer…
0
votes
1 answer

Mysql derived table order by

If I run the following query: SELECT * FROM `smp_data_log` WHERE Post_id = 1234 AND Account_id = 1306 ORDER BY Created_time DESC I get 7 rows back including entries with the following Created_times: 1) 1424134801 2) 1424134801 3) 1421802001 4)…
Antony
  • 3,875
  • 30
  • 32
0
votes
0 answers

Should I use one table if derived tables would all use the same record layout?

I'm developing a game SDK, which centers on establishment and persistence of storyline, characters, leveling, etc. I started with a mindmap of the different classes, and am now in the process of bringing those simple representations into UML. Since…