John Davidson

php - SELECT * FROM WHERE (using column from another table)

0 comments
Message:


I have two tables in MySQL, 1st table is called "receipt" the 2nd one is "scoreboard"


receipts Table:



Here is the scoreboard table >>



I need SQL to select from COL 7 where [COL3] = [scorekey] AND [COL 5] = [Selection]


and echo to div echo "<div>". $scr["COL 7"] ."</div>"


I tried join the two table, and my code is not working:


$score = "SELECT COL7
FROM scoreboard
LEFT JOIN scorekey ON receipts
WHERE scoreboard = scorekey";


$scr = $connection->query($score);



My Answer:
table1 and the 2nd table is called table2. I want to select all columns from table1 where the column value matches a column value in table2.

Here is the SQL query to achieve this:

sql
SELECT table1.*
FROM table1
JOIN table2 ON table1.column_name = table2.column_name;


In this query, replace `column_name` with the actual column name that you want to use for comparison between the two tables. This query will select all columns from table1 where the values in the specified column match in both tables.

Rate this post

3 of 5 based on 5439 votes

Comments




© 2024 Hayatsk.info - Personal Blogs Platform. All Rights Reserved.
Create blog  |  Privacy Policy  |  Terms & Conditions  |  Contact Us