SQL Query Select from 1 table and return data based on 2 columns

SQL Query Select from 1 table and return data based on 2 columns

Content Index :

SQL Query Select from 1 table and return data based on 2 columns
Tag : sql , By : lamberms
Date : January 12 2021, 07:00 PM

To fix this issue Why are you using temporary tables for this? These just make code harder to debug and maintain, more expensive to run, and more complicated to understand.
JOINs will work without temporary tables. But you do have to additional logic to get the give and receive values in separate columns, so more JOINs are necessary:
SELECT r.id, r.give, r.[receive], r.[type], r.[description], 
       r.isApproved, r.photoGive, r.photoReceive,
       pg.Photo as give_photo, pg.Employee as give_employee,
       pr.Photo as receive_photo, pr.Employee as receive_employee
FROM Intranet.dbo.Recognize r LEFT JOIN
     Vision7.dbo.SEUser sg
     ON r.give = sg.Username LEFT JOIN
     Vision7.dbo.SEUser sr
     ON r.receive = sr.Username LEFT JOIN
     Vision7.dbo.EMPhoto pg
     ON sg.Employee = pg.Employee LEFT JOIN
     Vision7.dbo.EMPhoto pr
     ON sr.Employee = pr.Employee

No Comments Right Now !

Boards Message :
You Must Login Or Sign Up to Add Your Comments .

Share : facebook icon twitter icon

MYSQL Query to SELECT row based on a value (if exists) otherwise return data from another table

Tag : mysql , By : user133834
Date : March 29 2020, 07:55 AM
should help you out Just use a LEFT OUTER JOIN between the two tables, so you will always have data corresponding to the table on the LEFT side of the JOIN:
SELECT C.itemName, C.itemCode, O.itemPrice, ...

Select data from one table & then rename the columns based on another table in SQL server

Tag : sql , By : wrb302
Date : March 29 2020, 07:55 AM
Does that help You can use dynamic sql to generate the query to execute based on the values in the first table. Here is an example:
Declare @dynamicSQL nvarchar(200)
EXECUTE sp_executesql @dynamicSQL

Query to return new columns based on the data in a single column

Tag : sql , By : Fernando
Date : March 29 2020, 07:55 AM
may help you . I saw this post (SQL - Query to seperate single column and create new columns based on column data) and wanted to comment on it, however, I don't have enough rep. I want to do the exact same thing, but I want to sum the values in the column(s) that are created for the case statements. , You can apply sum on case like this(column names assumed):
    sum(case when status = 'A' then value end) SUM_A,
    sum(case when status = 'B' then value end) SUM_B,
    sum(case when status = 'C' then value end) SUM_C,
    sum(case when status = 'D' then value end) SUM_D
from your_table
group by name;

how to return value when using linq query to select multiple columns from joined table?

Tag : chash , By : Theo
Date : March 29 2020, 07:55 AM
hope this fix your issue You can create a different class as you mentioned or else can return Tuple if you don't wanna create separate class. https://msdn.microsoft.com/en-us/library/system.tuple(v=vs.110).aspx is the official link about Tuple.

Check values in columns of data table and return new table based on condition in R

Tag : r , By : Gazza
Date : March 29 2020, 07:55 AM
this one helps. In base you can use rowSums for the specific columns to see if there is any 1 per row like:
tt  <- sapply(list(c("V4", "V5", "V6"), c("V7", "V8", "V9"))
              , function(i) sum(rowSums(x[,i]) > 0))

data.frame(label=c("con1", "con2"), fragnum=nrow(x), covered=tt
         , uncovered=nrow(x) - tt)
#  label fragnum covered uncovered
#1  con1       4       2         2
#2  con2       4       1         3
x <- structure(list(V1 = c(1L, 1L, 1L, 1L), V2 = c(1L, 7506L, 10943L, 
13169L), V3 = c(7512L, 10949L, 13175L, 20070L), V4 = c(1L, 0L, 
0L, 0L), V5 = c(0L, 0L, 0L, 1L), V6 = c(0L, 0L, 0L, 1L), V7 = c(0L, 
0L, 0L, 0L), V8 = c(0L, 0L, 0L, 0L), V9 = c(0L, 1L, 0L, 0L))
, class = "data.frame", row.names = c(NA, -4L))
Related Posts Related QUESTIONS :
  • update column with concatenating for that group only
  • SQL `SELECT 'some string value' AS fieldname` equivalent in Powershell?
  • How to determine the AVERAGE number of associated records
  • In Django, how can I build a set of criteria from a list?
  • Using replace() inside a loop
  • select user on create view
  • Calculate and aggregate column depending on a value in another colum (SQL)
  • Trigger to track all the insert or update on Oracle Table
  • Update column - remove first and last characters
  • T-SQL - Adding FK to table, make it do drop/null/efault automagically?
  • Get constraints and indexes on materialized views
  • SQL perform AVG after MAX
  • How do you join two tables A and B in order to get a non join column in A with data not in B?
  • Move Non-NULL Values Up Within Partition
  • Selecting rows based on two many-to-many relations
  • I have a table on which i want to do some advance calculation and get the table in a new shape
  • How to convert decimal to time in Oracle SQL?
  • Combine numbers to 1 row
  • Error: column does not exist when in fact it does? why?
  • How to fix: "Operation must use an updateable query" on update statement in Access VBA
  • Does information passes to a new table via CREATE TABLE update itself?
  • How to write a SQL statement which filters between two dates/times, with the date and time in separate columns
  • MS-Access-2016 Query Language 'ORDER BY' Clause
  • How to get totals for each age category?
  • get the first n characters of getdate()
  • Query to handle the dates
  • SQL grouping/counting on a string split function
  • ORDER BY and TOP statements in SQL works different on listing down the records and why?
  • SQL Server Computed Column: how to set it to NOT NULL, without persistence
  • Is nested select statement better than where statement?
  • Postgresql sequential scan slow performance on 500 million rows
  • Aggregate first order data to all orders - Microsoft SQL Server
  • Sorting comma delimited datasets in row
  • Question about the correct data structure
  • Showing two temp tables data in a single table
  • How can I find out the query execution time in Oracle SQL using Toad?
  • convert quarter number to month name in sql
  • Find max value from column that has a json object with key-value pairs
  • case statement based on 3 columns in 1 table
  • How to write a SQL query to select batsman wiht highest score than the previous year
  • Find Substring in SQL
  • Using VALUE to make temporary table
  • What is the correct way of writing an exclusive left-join on two tables?
  • Is it possible to run a make table query using a recordset as the source in MS Access (VBA)?
  • INSERT INTO select distinct null PostgreSQL
  • Why converting date from nvarchar(max) to date throws error?
  • how to fix wm_concat in oracle 12c
  • How to UNION a list of tables retrieved from another table with a single query?
  • Oracle query to get a relational dataset result from multimensional table
  • What algorithm is used in a hash partition that it can divide up the data into similar size partitions before seeing any
  • Why does my SQL return unwanted records with my OR in Where clause
  • SQL Multiple Joins Query-Query tuning
  • How to choose max of one column per other column
  • Query that returns rows that have both values in an IN statement
  • Select Unique records from table
  • SQL Query "Select latest record where active flag = 1"
  • SQL How to pivot two columns of data into different columns?
  • SQL Server : taking values doubling it and inserting into new column 20x
  • How to check a string is numeric using Regex in SQL Server?
  • SELECT query with Literal characters(Colon, Semi-colon) in Oracle
  • shadow
    Privacy Policy - Terms - Contact Us © scrbit.com