Linking two MySQL tables [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 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.

Related

Show in the tables, only the last statues [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 2 years ago.
Improve this question
I have a simple entry in the oracle, there are 3 columns, date, API name and status. I want that in the answer I had not all history, and only the last on each of Names of API (only 7). I will be grateful for your help. I know that asked of the very difficult but I'm just new to oracle.
select l.log_date,l.job_name,l.status from user_scheduler_job_log l
could be you want the related status for name and last log_date
select u.job_name, u.status, t.max_date
from user_scheduler_job_log u
INNER JOIN(
select MAX(l.log_date) max_date, l.job_name
from user_scheduler_job_log l
GROUP BY l.job_name
) t on t.max_date = u.log_date
AND t.job_name = u.job_name

MySQL select from two tables and combine results? [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 7 years ago.
Improve this question
I have a question about MySQL: I want to list results from a table but gather additional information about these results from another table by a foreign key.
My table YTPrograms has a foreign key called Author which corresponds to the Id of a second table called YTUsers from which I want to add the username to my result from the YTPrograms query. I'm not sure how to do this without having to query (the users table) for each result.
Try this:
SELECT p.something, u.username FROM YTPrograms p, YTUsers u WHERE p.Author = u.Id

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

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

mysql query for the following problem? [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 have three tables say 'user', 'user_resources' and 'desktop_resources'.
'user' contains - emp_id,name and other attributes
'user_resources' - emp_id and desktop_id foreign key relation
'desktop_resources' - desktop_id and other attributes
Now i want a sql query from where i can get a table which shows me name from 'user' table and 'desktop_resources' attributes only where "emp_id=d_id"
how to go about it??
I don't see d_id column there, but if you think so, it would look like this:
SELECT name, desktop_resources.*
FROM desktop JOIN user_resources USING (desktop_id) JOIN user USING (emp_id)
This is a straightforward series of joins:
select u.name, dr.*
from user u
join user_resources ur on ur.emp_id = u.emp_id
join desktop_resources dr on dr.desktop_id = ur.desktop_id
where u.emp_id = $d_id
Finally found this query useful:
SELECT name, desktop.*
FROM desktop
NATURAL JOIN (
user
JOIN user_resource ON user.emp_id = user_resource.emp_id
)
I am sure there may be other ambiguous queries for this..if u have got a better query..please put it in comments...