logo
down
shadow

Select Column within a Column SQL


Select Column within a Column SQL

By : Yesser Aouey
Date : November 20 2020, 03:01 PM
around this issue What I would do is use a table alias C1 for the original query. I would then sub-query the course description for the prerequisite course number, using a table alias C2. Notice I use both table alias- C1 and C2- associating the C2.Course_No number with the C1.PREREQUISITE number. The C2.DESCRIPTION is selected from this subquery. The subquery is given a column alias [Prerequisite Course Description]; note that without a column alias the field would have a blank header.
Should you use recursion? In this case you are probably not supposed to attempt such a solution unless you are specifically told to do so.
code :
  SELECT C1.Course_No 
        ,C1.PREREQUISITE, 
        ,(SELECT C2.DESCRIPTION 
            FROM COURSE AS C2 
           WHERE C2.Course_No = C1.PREREQUISITE
         ) AS [Prerequisite Course Description]
   FROM COURSE AS C1
  WHERE C1.Course_NO < 400
        C1.AND Course_NO >= 300


Share : facebook icon twitter icon
For every column in a sheet search for a value in a cell, then select that column and insert a column before that one

For every column in a sheet search for a value in a cell, then select that column and insert a column before that one


By : Vaibhav
Date : March 29 2020, 07:55 AM
I think the issue was by ths following , I was trying to write a macro that performed the following: , This will get you what you are after, I think.
code :
Dim wks As Worksheet

For Each wks In ThisWorkbook.Worksheets

    With wks
        Dim intCol As Integer, intCnt As Integer

        intCol = .UsedRange.Columns.Count

        For intCnt = intCol To 2 Step -1 'assumes you ignore col A since your match value is there
            If .Cells(5, intCnt) = .Cells(1, 1) Then
                .Range(.Cells(1, intCnt), .Cells(1, intCnt + 1)).EntireColumn.Insert Shift:=xlToLeft
            End If
        Next

    End With

Next
SELECT Only Records With Duplicate (Column A || Column B) But Different (Column C) Values

SELECT Only Records With Duplicate (Column A || Column B) But Different (Column C) Values


By : Yo Yo Nguyen
Date : March 29 2020, 07:55 AM
To fix this issue I apologize for the confusing title, I can't figure out the proper wording for this question. Instead, I'll just give you the background info and the goal: , I would do:
code :
SELECT first_name, last_name, COUNT(DISTINCT activity_id)
FROM <table_name>
GROUP BY first_name, last_name
HAVING COUNT(DISTINCT activity_id) > 0;
Dplyr or R basis. How to select (or delete) lines that have identical values (column 1 and column 2) and keeping column

Dplyr or R basis. How to select (or delete) lines that have identical values (column 1 and column 2) and keeping column


By : Sudipta Jash
Date : March 29 2020, 07:55 AM
I hope this helps you . In dplyr, use filter to retrieve specific rows and use select to retrieve specific columns.
For data.frames you need to as.character to match strings:
code :
library(dplyr)
test %>%
  filter(as.character(column1) == as.character(column2))
Ambiguous column name when select a column to return value if column is available in table by Execute Dynamic SQL comman

Ambiguous column name when select a column to return value if column is available in table by Execute Dynamic SQL comman


By : asdf
Date : March 29 2020, 07:55 AM
around this issue I want to return a column value if column is available in table,if not, return a default value, then I face COLUMN_NAME ambiguous error when join two table SHAIN1 and RIREKI14. If select from only one table then query works ok but if I join two table, I face problem. , This is your logic:
code :
declare @sql nvarchar(max) = '
SELECT 1 as id, '+
    (case when exists (SELECT 1 FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_SCHEMA  = 'dbo' and TABLE_NAME = 'RIREKI14' and COLUMN_NAME = 'KOM001')
          then 'KOM001'
          else 'NULL'
     end) + ' as day ' + '
From RIREKI14 join
     SHAIN1
     on RIREKI14.INCODE = SHAIN1.INCODE
';

exec sp_executesql @sql;
declare @sql nvarchar(max) = '
SELECT 1 as id, '+
    (case when exists (SELECT 1 FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_SCHEMA  = 'dbo' and TABLE_NAME = 'RIREKI14' and COLUMN_NAME = 'KOM001')
          then 'r.KOM001'
          else 'NULL'
     end) + ' as day ' + '
From RIREKI14 r join
     SHAIN1 s
     on r.INCODE = s.INCODE
';

exec sp_executesql @sql;
SQL Select vale for Column A Row 1, then Value from Column B Row 1, then Column A Row 2...all on separate rows

SQL Select vale for Column A Row 1, then Value from Column B Row 1, then Column A Row 2...all on separate rows


By : Dario006
Date : March 29 2020, 07:55 AM
Does that help It looks like your original order is by (fid, sid).
CROSS APPLY below essentially generates two rows for each original row. So, we are preserving the original order by (fid, sid) and making sure that values from column fid come first and from sid come second by adding the SortOrder column.
code :
SELECT
    CA.ID
FROM 
    YourTable
    CROSS APPLY
        (VALUES (fid, 1), (sid, 2)) CA(ID, SortOrder)
ORDER BY
    YourTable.fid,
    YourTable.sid,
    CA.SortOrder;
Related Posts Related Posts :
  • How to create table via ODBC in ansi sql compliant way?
  • Postgres. How to get all the parents that meet the childs criteria?
  • 'Exploratory' SQL queries that uses one criteria to find more criteria
  • Adding Date columns
  • Display ContactName from Guid in Gridview using SQLDataSource / Asp.Net
  • making groups based on match between column 1 and column 2 from 1 table
  • Teradata 15.10 - Remove set of characters from a string
  • PostgreSQL array_agg(INTEGER[])
  • Does a query goes through all data when you only select the last N?
  • Displaying results based on customer first order after specific date SQL Server
  • Sum records and add note what was summed up in sql
  • Need help in generating values
  • RODBC - import a table
  • SQL: How to Group By task and choose only those that are completed?
  • PostgreSQL/PostGIS Count number of visits
  • How to I get a total count?
  • Many-to-many SQL relationship
  • Procedure call inside procedure
  • How to have decreasing running total in Oracle sql
  • SQL Group function query?
  • Which is the best way to calculate Year/Month in SQL Server?
  • Best way of sanitize unparametrizable sql
  • Querying for JSON data in Oracle creates syntax error
  • Show top 1 by max column
  • SQL: Insert newly created column in the same table
  • How to extract numbers after string using regexp?
  • SQL Query - Group consecutive items based on condition
  • Users who work in same department
  • Syntax error near column value Vb
  • Oracle Trigger BEFORE INSERT has No data found
  • What kind of join to use on SQL tables
  • Is there a way to add a constant value dynamically to all records returned in Hive?
  • SQL optimization (inner join or selects)
  • EF 6.x, LINQ-to-SQL and raw SQL clauses
  • Simple SQL Variable Assignment Only Returns One Letter: Why?
  • Converting a custom timestamp to date
  • SQL Server : inserting Player vs Player names in to new table from tblEntrants
  • invalid identifier in sql
  • PL/SQL - I keep getting this error when concatenating: PLS-00306: wrong number or types of arguments in call to '||'
  • Count records only from left side of a LEFT JOIN
  • get everything before a string including itself oracle
  • Format Data from Word Doc to SQL using RegEX
  • Conditional formatting on MAX value row
  • MS-Access : selecting data from two tables and only returning you need
  • SQL Server: optimal indexing strategies for many-to-many join
  • DBgrid column very wide
  • PostgreSQL Group values by category, count and calculate percentage
  • MS Access SQL - Most Recent Record for Each Consultant ID
  • Update table: Summary of previous rows without using cursor or while loop
  • PostgreSQL: built-in function to remove substring starting with certain pattern
  • ORA-00909: invalid number of arguments
  • How to summarize all possible combinations of variables?
  • PostgreSQL Inserting 2 relationships at once
  • T sql - How to store results from a dynamic query using EXEC or EXECUTE sp_executesql
  • How do I parse my json into CSV using regex?
  • Reverse foreign key cascading (or how to collect database garbage)
  • SQL Pivot Questions
  • Insert records into a table with a condition in SQL Server 2016
  • display null value using rank functions in oracle sql
  • SQL - Get count of group by column but also select top item of group
  • shadow
    Privacy Policy - Terms - Contact Us © voile276.org