www.webdeveloper.com
Results 1 to 4 of 4

Thread: SQL Question

  1. #1
    Join Date
    Oct 2003
    Posts
    215

    SQL Question

    Let's say I have two SQL tables:

    table1
    t1_id, t1_title
    table2
    t2_id, t2_title

    I would like to return the titles and indexes from both tables in a single query, having the results ordered alphabetically by the titles.

    How can I accomplish this? I'm thinking with UNION but I can't quite get things to work.

  2. #2
    Join Date
    Nov 2003
    Posts
    655
    SELECT title, id FROM
    (SELECT title = t1_title, id = t1_id FROM table1
    UNION
    SELECT title = t2_title, id = t2_id FROM table2) X
    ORDER BY title

  3. #3
    Join Date
    Oct 2003
    Posts
    215
    Thanks!

  4. #4
    Join Date
    Nov 2003
    Posts
    655
    You're welcome

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
  •  
HTML5 Development Center



Recent Articles