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
Related
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 months ago.
Improve this question
Can anyone help me with this? I have doubts about the below function; can I create a virtual column for this?
select as1.col,as1.col2,as1.col3 from
analytics.adjusted_sale_velocity
where
date(as1.created_datetime)=(
select
max(
date(created_datetime)
)
from
analytics.adjusted_sale_velocity
)
MySQL optimizer won't use an index once a column in the WHERE clause is wrapped with a function, date in your case.
Your query might be written a little different:
select as1.col,
as1.col2,
as1.col3
from adjusted_sale_velocity a
inner join ( select max(created_datetime) as created_datetime
from adjusted_sale_velocity
) as max_dt on left(a.created_datetime,10) = left(max_dt.created_datetime,10) ;
Try and let me know if it is faster.
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.
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 3 years ago.
Improve this question
SELECT location,special,price FROM `tickets`
WHERE event = 'food' GROUP BY location
I think you want, (assuming its mysql) the following:
SELECT location, ANY_VALUE(special) special, ANY_VALUE(price) price
FROM tickets
WHERE event='food'
GROUP BY location ;
ANY_VALUE is strange aggregate function out of normal db standards that returns one of the values arbitarily.
If you wish to not have duplicate results in your rows you can choose only distinct result set.
SELECT DISTINCT location,special,price FROM tickets WHERE event = 'food' GROUP BY location
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.
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