What is the difference in MySQL between JOIN ON and WHERE? [closed] - mysql

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 2 years ago.
Improve this question
What is the difference in MySQL between:
SELECT * FROM A JOIN B ON A.item=B.item
and
SELECT * FROM A, B WHERE A.item=B.item

Multi FROM is similar to JOIN operation, you have to use WHERE clause to limit the rows returned. And it correspond to an implicit join.
But as you can read in comments, you should use explicit JOIN (OUTER JOIN, INNER JOIN, LEFT JOIN, RIGHT JOIN) that determine how the data is "linked" in ON clause.

Related

Not sure on Left Join, Outer Join, Unions or Minus? [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 5 years ago.
Improve this question
Current work requires my to have a complex level of SQL syntax including these examples.
What in short is a left Join and where would you use it?
What ever you have written is a JOIN clause that is used to combine rows from two or more tables, based on a related column between them.
Including outer join or left join depends on the table structure and the requirement to pull data from those tables.
IF you are looking for what is left join ,
Left join returns everything from the left table and the matching records from the right table and if there is no match in right table the result is null for the right table
Let us know what are you looking for

Mysql left join query returns values NULL [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 7 years ago.
Improve this question
My query:
SELECT DISTINCT img.prd_id,prd.*,img.* FROM products_prd prd OUTER JOIN
prd_images_img img ON prd.prd_id=img.prd_id ORDER BY prd.prd_datetime
the primary key in products_prd is returned NULL. They have values. while img.prd_id may be NULL or not.
The problem is that you have name collisions -- two things called prd_id for example. You need to use aliases to rename the columns:
SELECT prd.*, img.col1 as img_col1, img.col2 as img_col2
FROM products_prd prd LEFT OUTER JOIN
prd_images_img img
ON prd.prd_id = img.prd_id
ORDER BY prd.prd_datetime;
You don't need to select prd_id twice.
Or, you can use USING instead of ON:
SELECT *
FROM products_prd prd LEFT OUTER JOIN
prd_images_img img
USING (prd_id)
ORDER BY prd.prd_datetime;
This returns the columns in the USING clause only once (although you could have problems with other columns if they have the same names in the two tables).

SQL Command Error [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
I'm new with SQL, can anybody answer me what's the problem?! Thanks.
SELECT
bom.Parent_Material_Number,
mm.Material_Number,
mm.Material_Descr_HU,
bom.Child_Material_Number
FROM mm,bom
GROUP BY mm.Material_Descr_HU
Your query is wrong. If you intend to use GROUP BY clause, be sure that the Ungroup fields have an aggregates such as SUM(), MIN(), MAX(), etc. See my example below:
SELECT
MIN(bom.Parent_Material_Number),
MAX(mm.Material_Number),
mm.Material_Descr_HU,
MIN(bom.Child_Material_Number)
FROM mm,bom
WHERE bom.Parent_Material_Number = mm.Material_Number
GROUP BY mm.Material_Descr_HU;
You can also an explicit join. See below:
SELECT
MIN(bom.Parent_Material_Number),
MAX(mm.Material_Number),
mm.Material_Descr_HU,
MIN(bom.Child_Material_Number)
FROM mm INNER JOIN bom
ON bom.Parent_Material_Number = mm.Material_Number
GROUP BY mm.Material_Descr_HU;
I see that you take records from two tables mm and bomz FROM mm,bomz and have no join clause for this one in your statement.
you need a JOIN or a WHERE clause to link the tables together

Linking two MySQL tables [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
Even this is asked a billion times here already, none of them has worked for me.
So: I have two tables:
banhammer_bans:
and banhammer_players:
What sort of query should I make that it gets the name value from the "players" table corresponding to the "player_id" and "creator_id" value? I've tried with JOINS and UNIONS but no success.
Select p.name, p.id as player_id, b.creator_id as creator_id
from banhammer_bans as b
inner join banhammer_players as p on p.id = b.player_id
You can use something like this:
select
*
from
banhammer_bans, banhammer_players
where
banhammer_players.player_id = banhammer_bans.id
This is a kind of Join too, but it has some sort of efficiency problems.

How to get an attribute of parent of a table in sql stored procedure? [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
I want to write a select stored procedure and in the where clause I want to check value of a field of the parent table of the curent table which I am performing the select query On , How can I acheive this ?
any helps would be appreciated
You'll nedd to JOIN those tables. Without knowing the tables definition, your query should look something like this:
SELECT C.* --- List the columns you want here
FROM ChildTable C
INNER JOIN ParentTable P
ON C.ParentID = P.ID --- something along this lines
WHERE P.SomeField = 1 --- put here your condition on the parent table