Results 1 to 6 of 6

Thread: select in a row

  1. #1
    Join Date
    Apr 2015
    Posts
    3

    Unanswered: select in a row

    good morning,

    i have a table like the following... with much more columns and rows....

    c 3 b 2 d 4 c 3
    b 2 a 1 c 3 e 5
    a 1 c 3 e 5 b 2
    d 4 e 5 b 2 a 1
    e 5 d 4 a 1 d 4

    i have to select only the "a" value in a column and the corrisponding 1 value (that is the cell immediatley at the right of the "a" cell)
    the "a" value never is on the same column.

    the table should be like this

    a 1
    a 1
    a 1
    a 1


    "a" is always the same string. 1 is a value that changes everytime... i called 1 only for the example. 1 is the cell that follows the "a" cell on the same row.

    please help !

  2. #2
    Join Date
    Apr 2015
    Posts
    3

    query on a very "diffucult" table

    good morning

    i have a table like the following (with mmuch more rows and columns...)
    Code:
    c	3	b	2	d	4	c	3
    b	2	a	1	c	3	e	5
    a	1	c	3	e	5	b	2
    d	4	e	5	b	2	a	1
    e	5	d	4	a	1	d	4
    i have to select the "a" cell in a column. then for each "a" i have to select the corrisponding cell following on the right on the same row (i named them "1" but the values contained in the "1" cell is everytime different). the "a" cell contains everytime the same string.

    so the table resuld should be
    Code:
    a	1
    a	1
    a	1
    a	1
    thank you ! i am not a sql expertise .... so i am trying for 2 days...
    Last edited by gvee; 04-01-15 at 08:38. Reason: [code] tags added for formatting

  3. #3
    Join Date
    Apr 2015
    Posts
    3

    query on a table ... without apparent order....

    good morning

    i have a table like the following (with mmuch more rows and columns...)

    c 3 b 2 d 4 c 3
    b 2 a 1 c 3 e 5
    a 1 c 3 e 5 b 2
    d 4 e 5 b 2 a 1
    e 5 d 4 a 1 d 4

    i have to select the "a" cell in a column. then for each "a" i have to select the corrisponding cell following on the right on the same row (i named them "1" but the values contained in the "1" cell is everytime different). the "a" cell contains everytime the same string.

    so the table resuld should be

    a 1
    a 1
    a 1
    a 1


    thank you ! i am not a sql expertise .... so i am trying for 2 days...

  4. #4
    Join Date
    Jan 2007
    Location
    UK
    Posts
    11,434
    Provided Answers: 10
    Code:
    SELECT col1
         , col2
    FROM   your_table
    WHERE  col1 = 'a'
    
    UNION ALL
    
    SELECT col3
         , col4
    FROM   your_table
    WHERE  col3 = 'a'
    
    UNION ALL
    
    ...
    George
    Home | Blog

  5. #5
    Join Date
    Dec 2007
    Location
    Richmond, VA
    Posts
    1,328
    Provided Answers: 5
    I would ask for a better designed structure.
    Dave

  6. #6
    Join Date
    Jan 2013
    Posts
    354
    Provided Answers: 1
    I have a table like the following... with much more columns and rows....*
    Please follow basic Netiquette and post the DDL we need to answer this. Follow industry and ANSI/ISO standards in your data. You should follow ISO-11179 rules for naming data elements. You should follow ISO-8601 rules for displaying temporal data. We need to know the data types, keys and constraints on the table. Avoid dialect in favor of ANSI/ISO Standard SQL.

    This is vague and useless.

    c 3 b 2 d 4 c 3
    b 2 a 1 c 3 e 5
    a 1 c 3 e 5 b 2
    d 4 e 5 b 2 a 1
    e 5 d 4 a 1 d 4

    I have to select only the "a" value in a column and the corresponding 1 value (that is the cell immediately at the right of the "a" cell) the "a" value never is on the same column.*
    Columns have no ordering, so there is no left or right nieghbor! We locate them by a data element name.

    On a scale from 1 to 10, what color is your favorite letter of the alphabet? Yes, your question is that silly!

    the table should be like this*

    a 1
    a 1
    a 1
    a 1
    NO!NO!NO! A table has to have a key; it cannot have duplicate rows. This is not an option, but a definition. You cannot get this as a valid answer in SQL.

    please help !
    In the words of Mark Twain, “The pumpkin is a failure as shade tree”; this is a class array programming exercise, not an RDBMS problem. And not SQL. My Pascal is rusty, but you need something like:

    ARRAY Foobar [1:100] [1:100] OF CHAR

    Now use two loops to find A[j, i] and A[j, i+1] pairs.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •