0

I currently have one large data set that has the following columns and rows as an example.

       Latest   Name   Code    Date         Number  
         Y      abc    def     9/10/2017    123
         N      abc    def     10/10/2014   123
         N      abc    def     08/08/2008   123

I need to change the output so that it reads as follows:

      Latest   Name   Code    Date         Number  Latest   Name   Code   Number
         Y      abc    def     9/10/2017    123      N      abc    def     10/10/2014   123
         Y      abc    def     9/10/2017    123      N      abc    def     08/08/2008   123

I have thought through the issue and I think I need to split the table into 2 smaller tables, one with Y as Latest and one with N as Latest then use an inner join to match the results? can anyone help me with this please? I have tried the following:

      CREATE Table Latest AS
      SELECT * 
      FROM [Original Table]
      WHERE Latest = 'Y'

      CREATE Table Latest AS
      SELECT * 
      FROM [Original Table]
      WHERE Latest = 'N'

However I'm getting an error when I tried to run the queries - Incorrect Syntax near SELECT, expecting ID

When it comes to the join I intend to join these using the code column. Can anyone help please?

3
  • Based on the syntax, I removed the MySQL tag. Please tag with the database you are really using. Commented Sep 14, 2017 at 21:49
  • @GordonLinoff The problem was that he was trying to use MySQL CREATE TABLE syntax on SQL-Server. Commented Sep 14, 2017 at 21:51
  • Not sure if I'm misunderstanding why you want to do this, but you don't actually need to create two tables just to join them together. You can join the table to itself with appropriate conditions. Commented Sep 14, 2017 at 21:52

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.