Sql statement problem

there are two tables, one document table and one case table


document (id,case_num,document_name)


case (id,case_num,case_name,status)

the case_num of the document table corresponds to the case_num of multiple case tables
the case_num format of the document table is separated by ", sign", for example:

A001,A002

the problem is to add the contents of the two tables to the third table. The condition is that the status of all the records in the corresponding case table in the case_num field of the document table is"1"

.

could you tell me how to click on this sentence

Feb.08,2022

this is not easy to write. if you have to write, you need to first take out the case_num string in the document table, traverse in the program, and traverse each to query the case table.

if possible, restructure the table. Generally, this relationship is expressed in an intermediate table.

document(id,document_name)
case(id,case_name,status)
-sharp 
document_case(id,document_id,case_id)

then query

like this
 

it is recommended to adjust the table structure.
you actually violate the principle of the first paradigm of database design by storing multiple values in a field.
if the field itself does not participate in any operation, but is simply stored, then it is not a big problem to reverse the normal form here.

but you are obviously involved in the calculation here. So if the performance and data consistency is relatively large, it is recommended to adjust the table structure as suggested by the brother upstairs.

MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1b3c680-2c315.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1b3c680-2c315.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?