where clause when using 'with' in relational mode
Hey there. I am sqlite (turso)
schema
course table
courseMember
Course member is a join table between the course and userId
a user can have many courses and a course can have multiple user with a role
I want to fetch the courseMember and their related course. But I also want to use the search functionality. So how can I use the where clause inside with
I need your help regarding this
6 Replies
basically it's many to many relationship.
I have seen example of one to many in the docs using
where
clause in with
.
Even one to many works for me
But in this case I am not able to use the where
clause
bump..
Anyone please
Sorry for tagging but I couldn't find any help
@Angelelz @Dan KochetovFeel free to tag me whenever you need
Let me take a look at your cose
Code
Ok, so the error you see is because a courseMember is related to only one course when seen from the connecting table. The where doesn't show up, because it will be only one row, you either want it or not
Can you explain that you would like to get from this query and I can help you put it together
i believe i have a similar issue https://discord.com/channels/1043890932593987624/1230519866113654785 do you think you could share some insight 😓
Thank you so much Angelelz for the reply.
I want all the courses of the particular member. I am able to achieve this
Response:
But when I type the search query I want only matching course name
so I want to use the where clause with like..
In that case I would do it like this:
Basically you are using a subquery inside the where. Pulling the courseId that corresponds to the title you need, and then search for that courseId
Btw, you could include metadata in the connecting table. For example, you can put the course title there, it would make the query a lot easier
This is an interesting technique but you have to try to not abuse it
Thank you so much Angelelz. This works for me. Also thanks for suggestion for having title in the join table.
I will try to explore more inArray thing.
Just a little correction the courseMember.courseId will be first arguement
Again thank you for support. Really Appreciate it