Aligning multiple query results

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • kiqyou_vf

    Aligning multiple query results

    Sorry, Google wouldn't let me post a reply. Here is the convo thus far:

    Jerry Stuckle wrote:[color=blue]
    > kiqyou_vf wrote:[color=green]
    >> I'm trying to pull data from 2 different tables and do a loop to
    >> retrieve more than one row. I'm having problems with aligning the
    >> information. Can someone lead me in the right direction? I've done some
    >> looking myself and found something called GROUP BY? Is that what I need
    >> to use? Thanks in advance.[/color][/color]
    [color=blue]
    > Sorry, my mind reading isn't working this morning.[/color]

    [color=blue]
    > It's impossible to tell without knowing the structure of your tables,
    > the code you're using and the output you expect.[/color]



    Sounds more like a UNION problem, but Jerry is right. We need more
    information to make reasonable comments.

    -david-


    I have a page that displays multiple search results. On each search
    result I want unique information from two or more tables to be
    displayed. All tables have a "client_id" column. I need the main query
    to display results based on the $_GET['keywords'] and a second table to
    display results based on the "client_id" of the main query. I don't
    have any code as of yet to show you. I have done some research on UNION
    and found this on mysql.com:

    "Selected columns listed in corresponding positions of each SELECT
    statement should have the same type. (For example, the first column
    selected by the first statement should have the same type as the first
    column selected by the other statements.) The column names used in the
    first SELECT statement are used as the column names for the results
    returned."

    Is this going to be a problem since the names and information are going
    to be different on each of my tables.

  • Michael Austin

    #2
    Re: Aligning multiple query results

    kiqyou_vf wrote:
    [color=blue]
    > Sorry, Google wouldn't let me post a reply. Here is the convo thus far:
    >
    > Jerry Stuckle wrote:
    >[color=green]
    >>kiqyou_vf wrote:
    >>[color=darkred]
    >>>I'm trying to pull data from 2 different tables and do a loop to
    >>>retrieve more than one row. I'm having problems with aligning the
    >>>informatio n. Can someone lead me in the right direction? I've done some
    >>>looking myself and found something called GROUP BY? Is that what I need
    >>>to use? Thanks in advance.[/color][/color]
    >
    >[color=green]
    >>Sorry, my mind reading isn't working this morning.[/color]
    >
    >
    >[color=green]
    >>It's impossible to tell without knowing the structure of your tables,
    >>the code you're using and the output you expect.[/color]
    >
    >
    >
    >
    > Sounds more like a UNION problem, but Jerry is right. We need more
    > information to make reasonable comments.
    >
    > -david-
    >
    >
    > I have a page that displays multiple search results. On each search
    > result I want unique information from two or more tables to be
    > displayed. All tables have a "client_id" column. I need the main query
    > to display results based on the $_GET['keywords'] and a second table to
    > display results based on the "client_id" of the main query. I don't
    > have any code as of yet to show you. I have done some research on UNION
    > and found this on mysql.com:
    >
    > "Selected columns listed in corresponding positions of each SELECT
    > statement should have the same type. (For example, the first column
    > selected by the first statement should have the same type as the first
    > column selected by the other statements.) The column names used in the
    > first SELECT statement are used as the column names for the results
    > returned."
    >
    > Is this going to be a problem since the names and information are going
    > to be different on each of my tables.
    >[/color]

    it is a JOIN (implicit) not a UNION

    select a.id,a.col2,a.c ol3,b.col1,b.co 2,c.col1,c.col3
    from table1 a, table2 b, table3 c
    where b.id=a.id and c.id=a.id
    and a.id = 123;




    --
    Michael Austin.

    Comment

    Working...