0

I have two tables (Assessments, Unit_Assigned). In Assessments table I store Multiple Unit Assigned Ids with comma-separated Format like below

id | title | assignedids
-------------------------
2  | NTitl | 15,25,6
-------------------------
3  | Ctitl | 25,6,38

Unit_Assigned Table display below

id | staffid | unit_id | batchid
---------------------------------
15 | 10      |  25     |  31
---------------------------------
38 | 12      |  18     |  42
---------------------------------

I need to get an assessment list based on staff ID (available in Unit_Assigned table)

I got assigned ids list using below query

  $assignedunits=Unitassigning::Where('staffid',$staffid)->get()->pluck('id')->toArray();

try to fetch assessment using below query

$stringconverted=implode(",",$assignedunits); $completedAssessments=Assessments::whereRaw("find_in_set('$stringconverted',assignedids)")->get();

Karthik
  • 5,589
  • 18
  • 46
  • 78
  • 2
    Is this project still in development? If yes, you REALLY should considered a db redesign with a many-to-many relationship, since a unit can have many assessments and vice-versa (from what I understood). – hhelderneves Jul 10 '20 at 11:52
  • Does this answer your question? [MySQL find\_in\_set with multiple search string](https://stackoverflow.com/questions/5015403/mysql-find-in-set-with-multiple-search-string) – Digvijay Jul 11 '20 at 04:32

0 Answers0