MySQL : How to I, join this 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 12 months ago.
Improve this question
I have table like this, and i want to output the result like output table, can anyone tell me how to do it, in MySQL

You can use left join like so :
SELECT tb_session.SESSION AS SESSION, tb_class.CLASS AS CLASS from tb_schedul LEFT JOIN tb_session ON tb_schedule.ID_SESSION = tb_session.ID LEFT JOIN tb_schedul.ID_CLASS = tb_class.ID

Good morning, you can use LEFT JOIN
try it:
SELECT tb_session.SESSION, tb_schedul.ID_CLASS FROM tb_session LEFT JOIN tb_schedul
ON tb_session.ID = tb_schedul.ID_SESSION;

Related

Open Json a Json field in SQL Server to table [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 1 year ago.
Improve this question
I have a table in SQL Server where a row contains a Json column - something like this:
ResponseText
RequestId
{"LosUnqCod":0,"LosMidId":23}
96173722
{"LosUnqCod":1,"LosMidId":5}
96173721
I want to have a table in this shape:
LosUnqCod
LosMidId
RequestId
0
23
96173722
1
5
96173721
how to open this json?
Hi every body I found my answer and want to share with anyone who has the same issue as I does
SELECT
reqTbl.LosUnqCod ,
a.RequestId
FROM [dbo].[a] CROSS APPLY
OPENJSON( dbo.a.responsetext)
WITH (
LosUnqCod nvarchar(50)
) AS reqTbl
You don't have to use OPENJSON if you only have one JSON object (not an array) per SQL row, you can use JSON_VALUE instead:
SELECT
JSON_VALUE(a.responsetext, '$.LosUnqCod') LosUnqCod,
JSON_VALUE(a.responsetext, '$.LosMidId') LosMidId,
a.RequestId
FROM [dbo].[a];

Hive CASE WHEN THEN ISSUE [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 3 years ago.
Improve this question
Below is the code failing in Hive:
(Alias at 6:5 (END) is not recognized)
INSERT INTO WRKT_REGULATORY_COMPONE_RECLASS
select
case
when WRKT_REGULATORY_COMPONENT_FINAL.REVENUE_FLAG != 'Y'
AND WRKT_REGULATORY_COMPONENT_FINAL.EXCLUDED_FLAG = 'Y'
THEN WRKT_REGULATORY_COMPONE_RECLASS.EXECUTION_ORDER = '1'
END
FROM WRKT_REGULATORY_COMPONENT_FINAL
this one: THEN WRKT_REGULATORY_COMPONE_RECLASS.EXECUTION_ORDER = '1' is wrong
after THEN it should be literal 1 or column

Error While Deleting row from multiple dependent tables [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 4 years ago.
Improve this question
ERROR: syntax error at or near "r"
Query was:
Delete r,ur from un_received_compansation_reason ur join received_compensation_info r on received_compensation_info.compensation_info_id = un_received_compansation_reason.compensation_info_id where compensation_info_id=2
You have specific table aliases, so try writing the query as:
Delete r, ur
from un_received_compansation_reason ur join
received_compensation_info r
on r.compensation_info_id = ur.compensation_info_id
where r.compensation_info_id = 2;
You need to use table aliases in time joining key like below
Delete r,ur from un_received_compansation_reason ur join
received_compensation_info r on
r.compensation_info_id = ur.compensation_info_id
where ur.compensation_info_id=2

Replacing null by zero [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 need to write a query which need to replace email result by 0 when it's null
UPDATE tblName SET email = 0 WHERE email is null;
Use the ifnull() function:
ifnull(email,"0")
You can use the coalesce function:
SELECT COALESCE(email, '0') FROM some_table

mysql return a fixed number of queries [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
I have 3 mysql queries in php (one for each category/widget), all 3 queries together should output 3 * 6 = 18 results. So if one query returns less, more results from the other queries should be used.
How can i do that? Thanks.
Instantiate 2 variables , keep count of selected rows and execute query using these counters
for example this will be your first query execiton
$default = 6;
$limit= $default;
$some_result = mysql("SELECT * FROM table LIMIT $limit");
then you can use this for every query-limit
$limit = $limit - count($some_result) + $default;