MySQL to refer to row from same table [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 4 years ago.
Improve this question
I have a table named tblMitigation, which has several columns:
Headcode, Time, Origin, Destination, Mitigation, Next Service.
The Next Service column refers to another Headcode value in the same table. How can I use MySQL to look up the Mitigation column for that other service?
Thanks
Chris

You could JOIN the table to itself. Use a LEFT JOIN in case there is no Next Service as yet. The COALESCE will ensure the value of Next_Mitigation is something different in that case e.g. N/A
SELECT current.*, COALESCE(next.Mitigation, 'N/A') AS Next_Mitigation
FROM tblMitigation current
LEFT JOIN tblMitigation next ON next.Headcode = current.`Next Service`

Related

Is there any need of log table [closed]

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 6 months ago.
Improve this question
I am developing an application that has database of mysql having orders and orderdetails table. order table having column orderStatus. My question is whether it is necessary to create another order log table if order status is 'closed' (that means completed orders) or just orderstatus column is enough.
From what you have described, I would assume a column is sufficient.
You might need another table if:
An order can have more than one status at the same time
You need to keep a history of when the order changed status
There might be other cases that would require another table, but you haven't described that any such condition applies in your case, as far as I can tell.

How to get a specific row of data for mysql with specification of company and agent [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
How to retrieve all the data pertaining to company name and agent from mysql? How to write the query statement?
Have you tried this?
SELECT *
FROM agent_info
WHERE policyCompany = 'Avia' and policyAgent = 'Ron';
I have to guess because you didn't tell us much about your tables, but this might work.
SELECT policyCompany,
GROUP_CONCAT(DISTINCT policyAgent ORDER BY policyAgent) agents
FROM mytable
GROUP BY policyCompany
You can read about GROUP_CONCAT() here.

Select data from database [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
I want to load data from database but how to get data in specific colmun
More Explanation:
lets say that we have a table called players, Then we have three columns "Username, Password and E-mail"
Now, if we want to select the email of the player who called "Nezo" how we can do it ?
This is a straightforward SELECT statement. I'd take some time to familiarize myself with the MySQL manual on SELECT, since it is among the most basic MySQL commands.
In this case, our select_expr (SELECT expression) is going to be the column from the table we're looking for, E-mail, and we're going to need to restrict the query to only look at the e-mail of the user named 'Nezo' using a WHERE clause:
SELECT `E-mail` FROM `players` WHERE `Username` = 'Nezo';

How to Deactivate a row in mysql instead of Deleting [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 9 years ago.
Improve this question
How can I deactivate a row instead of deleting it, using flag values in MySQL?
Add an active column to the table, and then do:
UPDATE YourTable
SET active = 0
WHERE id = :id
to deactivate the row. You'll then need to update all other queries so they do:
WHERE active = 1
There's no built-in mechanism that does this automatically.
You can create a column in your table as type CHARACTER(1), and use something like 'A' for active and 'D' for deactivated.
There isn't a "flag value" for mysql, people refer to it as a flag, as they created the flag within their own tables for use as such.

MySQL select issue ( unique ) [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 a table with the following fields :
date / source / destination
The same source can go to the same destination but at different time.
Multiple sources can go to same destination, etc.
I am looking to extract all destinations that have unique sources.
Bit hard to try to help with so little info, but maybe this could work?
SELECT Destination
FROM tablename
GROUP BY Destination
HAVING COUNT(DISTINCT Source) = 1