Rows from 2 tables together

Discussion in 'PHP' started by Hade, Aug 14, 2008.

  1. #1
    Hi,

    I'm trying to get rows out of two tables and list them together. Using MySQL (and PHP)

    It must be all Mysql. I tried getting the rows seperately and merging the arrays with PHP bu I can't then to pagination.

    Here's what's in the tables:

    Table 1:

    id - name
    ----------
    1 Mary
    2 Robert
    3 Chris


    Table 2:

    id - name
    ----------
    1 John
    2 Dave
    3 Mike


    So I want the SQL statement to return the following (in any order):


    1 Mary
    2 Robert
    3 Chris
    4 John
    5 Dave
    6 Mike


    Thanks!
     
    Hade, Aug 14, 2008 IP
  2. php-lover

    php-lover Active Member

    Messages:
    261
    Likes Received:
    21
    Best Answers:
    0
    Trophy Points:
    58
    #2
    SELECT * FROM table1 UNION SELECT * FROM table2
     
    php-lover, Aug 14, 2008 IP
  3. Hade

    Hade Active Member

    Messages:
    701
    Likes Received:
    18
    Best Answers:
    0
    Trophy Points:
    90
    #3
    Thanks.
    I've resolved it a different way though.

    I simply created pagination for the array of data (the array merged from 2 different SQL calls). Works like a charm!

    Thanks anyway!
     
    Hade, Aug 14, 2008 IP