Yahoo Answers is shutting down on May 4th, 2021 (Eastern Time) and beginning April 20th, 2021 (Eastern Time) the Yahoo Answers website will be in read-only mode. There will be no changes to other Yahoo properties or services, or your Yahoo account. You can find more information about the Yahoo Answers shutdown and how to download your data on this help page.

MySQL query for multiple fields in different tables?

I have 2 different tables that I need to pull multiple fields from, but I am unsure how to do it correctly.

Can anyone shed some light on how I can accomplish this?

4 Answers

Relevance
  • Anonymous
    9 years ago
    Favorite Answer

    For that you'll have to use MySQL Join queries. They are like this one:

    SELECT table1.field1, table2.field1, table1.field2, table2.field2 FROM table1, table2 WHERE table1.field1=table2.field1

    but this was an implicit version. An explicit (better and more symantical) version of this would be:

    SELECT table1.field1, table2.field1, table1.field2, table2.field2 FROM table1 JOIN table2 ON table1.field1=table2.field1

    NOTE- the field (column) name must be prefixed with table name and a dot to get rid of ambiguity and confusion(in case both the tables have rows with same names)

    best of luck

  • 9 years ago

    You want to create something called a JOIN in SQL. Note that in practice, you need a common value in each table that you can use to "join" rows in each table. You probably want to do some more research on JOINs since it's a very fundamental tool for querying a database.

    Ex:

    SELECT student.name,grade.value FROM student,grade WHERE student.student_id=grade.student_id;

  • 5 years ago

    you do not get an blunders back in $effect. For attempting out you're extra ideal to adhere to the mysql_query() statement with or die (mysql_error()); do now no longer attempt to insert a null it gained't paintings. For the auto_increment field insert an empty, thoroughly different from null. So your first archives fee might want to be : values ('', it particularly is two unmarried expenses, now no longer a double quote.

  • 9 years ago

    You can join tables in your result with SQL joins.

    This website explains everything better than i could so i'd suggest you take a look:

    http://www.w3schools.com/sql/sql_join.asp

Still have questions? Get your answers by asking now.