+ Post New Thread
Results 1 to 9 of 9
Coding Thread, SQL Question in Coding and Web Development; Im not sure if i have put this in the right section..... I am wanting to do an query on ...
  1. #1

    Join Date
    May 2006
    Location
    Leicestershire
    Posts
    345
    Thank Post
    0
    Thanked 1 Time in 1 Post
    Rep Power
    0

    SQL Question

    Im not sure if i have put this in the right section.....

    I am wanting to do an query on a database, im using mysql.

    i want to query 3 fields on a single table but want the results to comeout as just one field. it was a long shot but i tried the following which didnt work, but might explain what i want to do

    Code:
    SELECT dt7 AS year7, ict7 AS year7, art AS year7 WHERE sID=1;
    this didnt work, can anyone shed some light as to how i can do this

    Thanks

    Nij

  2. #2

    Geoff's Avatar
    Join Date
    Jun 2005
    Location
    Fylde, Lancs, UK.
    Posts
    11,850
    Thank Post
    110
    Thanked 598 Times in 514 Posts
    Blog Entries
    1
    Rep Power
    227

    Re: SQL Question

    What is the data? numbers? do you want to add them up?

  3. #3

    Join Date
    May 2006
    Location
    Leicestershire
    Posts
    345
    Thank Post
    0
    Thanked 1 Time in 1 Post
    Rep Power
    0

    Re: SQL Question

    the data is alphanumeric data...... i want to query 3 fields form the table return the results as if it was 3 entries from a single field in the table...

    so i would want them returned as year7 and the result would be 3 individual rows from the fields ict7, dt7, art7 etc.....

  4. #4

    Geoff's Avatar
    Join Date
    Jun 2005
    Location
    Fylde, Lancs, UK.
    Posts
    11,850
    Thank Post
    110
    Thanked 598 Times in 514 Posts
    Blog Entries
    1
    Rep Power
    227

    Re: SQL Question

    Code:
    SELECT dt7 + ict7 + art AS year7 WHERE sID=1;

  5. #5

    Join Date
    May 2006
    Location
    Leicestershire
    Posts
    345
    Thank Post
    0
    Thanked 1 Time in 1 Post
    Rep Power
    0

    Re: SQL Question

    that adds the values together..... i want the results from each field as 3 individual results. individual rows

  6. #6

    Geoff's Avatar
    Join Date
    Jun 2005
    Location
    Fylde, Lancs, UK.
    Posts
    11,850
    Thank Post
    110
    Thanked 598 Times in 514 Posts
    Blog Entries
    1
    Rep Power
    227

    Re: SQL Question

    Then do 3 selects?

  7. #7

    Join Date
    May 2006
    Location
    Leicestershire
    Posts
    345
    Thank Post
    0
    Thanked 1 Time in 1 Post
    Rep Power
    0

    Re: SQL Question

    it would just make it easier to handle in PHP if i could get it to work like that, as i could just use the array....

    Im trying to get my script to generate dynamic graphs

  8. #8
    Iain's Avatar
    Join Date
    Oct 2006
    Location
    Warwickshire
    Posts
    197
    Thank Post
    28
    Thanked 98 Times in 56 Posts
    Rep Power
    36

    Re: SQL Question

    Hows about.....
    Code:
    (SELECT dt7 AS year7 WHERE sID=1)
    UNION ALL
    (SELECT ict7 AS year7 WHERE sID=1)
    UNION ALL
    (SELECT art7 AS year7 WHERE sID=1);
    Should give you one table with one column named year7 containing the data from the 3 SELECT queries.

  9. #9

    Join Date
    May 2006
    Location
    Leicestershire
    Posts
    345
    Thank Post
    0
    Thanked 1 Time in 1 Post
    Rep Power
    0

    Re: SQL Question

    thanks Iain.... i think u just hit the nail on the head, just what i was looking for and works aswell!

    Cheers mate!



SHARE:
+ Post New Thread

Similar Threads

  1. Here's a question for you!
    By azrael78 in forum Hardware
    Replies: 15
    Last Post: 1st October 2007, 11:33 AM
  2. Win 2k PDC question
    By glennw in forum Windows
    Replies: 2
    Last Post: 27th September 2007, 01:17 PM
  3. dvd question
    By strawberry in forum Hardware
    Replies: 3
    Last Post: 24th August 2007, 05:17 PM
  4. Question
    By Elky in forum Recommended Suppliers
    Replies: 48
    Last Post: 7th November 2006, 02:02 PM

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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