Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

MySQL query with condition from 2 tables

I’m new to programing and mysql and stuff I think this is simple but not for me So, I have those two table Tickets and Ticket_user and I need to get all the fieds from the Table Ticket where user_id =15 and ticket_id >8

Table 1 : Ticket

id             name          ...... other fields
7              Tickte1            
8              Tickte2  
9              ticket3
10             ticket4
11             Tickte5

Table 2 : Ticket_users

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

   id   ticket_id     User_id
   1     7             15           
   2     8             16
   3     9             15
   4     10            15
   5     11            8

Result

  ticket_id     name          ...... other fields
  9             Tickte3             
  10             ticket4

How can I achieve this ?
appreciate any help.

>Solution :

You need to look into JOIN CLAUSE.

What your looking for is something like this

SELECT t.* 
FROM Ticket t LEFT JOIN Ticket_users tu ON t.id = tu.ticket_id 
WHERE tu.user_id = 15 AND t.id > 8
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading