Extracting two columns from different tables in mysql

how to retrieve data from multiple tables in mysql
mysql> select from two tables at once
mysql> select from multiple tables
how to fetch data from two tables in mysql using php
how to retrieve data from multiple tables in sql
how to fetch data from two tables in mysql without join
join two tables without common column mysql
how to get data from two tables without joining them in oracle

How can I join two sql queries

 $sql = "SELECT Wpm FROM tableA limit 26"; and 
 "SELECT Rpm FROM tableB";

into one, and echo the results in the code below? I just want to display the two columns side by side in a table. I am not sure if the word "join" is the right one here. Thanks!

  <table class="tbresult">
        <tr>
            <th>Wpm</th>
            <th>Rpm</th>
        </tr>

        <?php

      include ("config.php");

****   $sql = "SELECT Wpm FROM tableA limit 26"; 
AND 
"SELECT Rpm FROM tableB";******


      $result = $conn->query($sql);
      if ($result->num_rows > 0) {

      $counter = 3;

       while($Row = $result->fetch_assoc()) 
       {
            echo "<tr><td>" . $Row["Wpm"] . "</td><td>" . $Row["Rpm"] . "</td></tr>";

                $counter++;
                if($counter % 33 == 0) { ?>
    </table>

    <table class="tbresult">
        <tr>
            <th>Wpm</th>
            <th>Rpm</th>
        </tr>

        <?php }
        }
    echo "</table>";

    } else { echo "0 results"; }
    $conn->close();
    ?>

I think you are looking for a "Cross Join" - a cross join produces a "carthesian product". This means it multiplies the rows of "Table A" and "Table B":

SELECT Wpm, Rpm FROM tableA cross join tableB 

(details here: https://www.w3resource.com/sql/joins/cross-join.php)

Retrieving Records from Multiple Tables, In Chapter 1, we devoted quite a bit of attention to single-table SELECT statements, concentrating primarily on the output column list and the  To get the results I want from each table separetelly I would do the following: SELECT `dt2` FROM `table1` WHERE `dt1`=7; and. SELECT `dt4`,`dt5` FROM `table2` WHERE `dt3`=3 LIMIT 0,1; One more thing, I don't want to use a subquery for each column, because in the real thing I'm trying to solve, I'm calling 5 or 6 columns from each table.

 $sql = "SELECT Wpm FROM tableA limit 26";
 $sql = "SELECT Rpm FROM tableB";

It means the second query runs every time because first variable replaced by second.

For this you need to run separate for first and second query.

MySQL Select Data from two Tables in 1 Query with out specifying , Don't use the *, instead specify all column names you want to extract. Good practice in a multiple table query is to specify the columns table as well: The problem in this query is that want to retrieve sum from two columns which resides in separate tables. 'chitante.val' has stored two records which must calculate the sum, and 'facturare.total' - in my case - has only one.

if columns are same and equal use UNION here . else its better to use JOINs than 2 select and fetch them. anyway your first $sql are replaced by second...

How to select two columns from two different tables using foreign , SELECT user.name, movie.name FROM user, movie, list WHERE list.user_id = user.id AND list.movie_id = movie.id ORDER BY 1,2;. Or, if you need to see the  Table Name: usageDB_january Column Name: user_id (CUSTOMER'S ID) , server_id (SERVER'S ID) Table Name: usageDB_december Column Name: user_id (CUSTOMER'S ID) , server_id (SERVER'S ID) NOTE: There are 12 tables from usageDB_january to usageDB_december

SQL SELECT INDIVIDUAL FIELDS FROM MULTIPLE TABLES , SQL SELECT INDIVIDUAL FIELDS FROM MULTIPLE TABLES - how to SELECT INDIVIDUAL Duration: 3:00 Posted: Apr 21, 2016 To list all the fields from a table in MySQL: select * from information_schema.columns where table_schema = 'your_DB_name' and table_name = 'Your_tablename'

MySQL Tutorial :: 4.4.9 Using More Than one Table, This is done by prepending the table name to the column name. You need not have two different tables to perform a join. Sometimes it is useful to join a table to​  MySQL also supports a nonstandard extension of the ANSI syntax that can be used as a sort of shorthand for when the join column has the same name in both joined tables: SELECT field1, field2, FROM my_table t1 JOIN my_other_table t2 USING (t1.id_field) WHERE t1.lastname = 'Smith';

Selecting Particular Columns, If you do not want to see entire rows from your table, just name the columns in which you are interested, separated by commas. For example, if you want to know  This will important when we start talking about multiple tables, especially when those tables have column names that are the same. Using aliases helps us specify which table a column belongs to. The syntax for table aliases is a little different than for column aliases, but the idea is the same. Consider one of our earlier example queries.

Comments
  • What are the structures of your tables? do they have a foreign key relationship?
  • what is the common column in both tables which can be used as reference to combine?
  • In the above code, the 2nd query will be executed always.
  • I think you need to use the join condition for your sql Query
  • thanks. the tables don't have a foreign key relationship. I just want to display the results side by side.
  • why is the answer downvoted? A cross join does exacty join 2 tables without a key: SELECT Wpm, Rpm FROM tableA cross join tableB
  • Tobias, I didn't downvote your answer. someone else did. I don't know why. I'll check your suggestion. I tried to do this myself, but couldn't find a simple explanation on joins. I don't know much about mysql/php, so I can't know if your answer is good or not.
  • While this link may answer the question, it is better to include the essential parts of the answer here and provide the link for reference. Link-only answers can become invalid if the linked page changes. - From Review
  • @Vinay Prajapati: you are right - I added a short explanation to the link
  • Thanks, Niraj.I don't want to run them separately, I want to join them.
  • sure can you than show me your table structure Please...because for join we need a common thing on both table
  • tableA has Wpm column which is basically letters from a to z. 26 rows. and tableB has columns ID,Rpm, Spm,Tpm,Kpm. they have no relationship.