0

I'm new on Python and would need some help for the following :

I'm building a CRM using Tkinter and Mysql database.

My database was quite big so I decided to split it into several tables (to avoid the VARCHAR limitation among other).

So far I have 5 tables named CRM1, CRM2, CRM3, CRM4, CRM5 and each one have a column "id" as primary key.

As I need to be able to search in the whole database I would like to JOIN all those 5 tables in one query but so far I only succeed to joining the first 2. when I add a second JOIN statement the query fails ...

Here is what I have working so far : (searched is an ENTRY box .get)

sql = "SELECT * " \
  "FROM CRM1 " \
  "JOIN CRM2 " \
  "ON CRM1.id = CRM2.id " \
  "WHERE " \
  "contact_last_name_1 LIKE '%" + searched + "%' OR " \
  "project_1_piano_brand LIKE '%" + searched + "%' ORDER BY CRM1.id DESC"

I tried to add another JOIN statement like this :

sql = "SELECT * " \
  "FROM CRM1 " \
  "JOIN CRM2 " \
  "ON CRM1.id = CRM2.id " \
  "JOIN CRM3 " \
  "ON CRM1.id = CRM3.id " \
  "WHERE " \
  "contact_last_name_1 LIKE '%" + searched + "%' OR " \
  "project_1_piano_brand LIKE '%" + searched + "%' OR " \
  "project_2_piano_brand LIKE '%" + searched + "%' ORDER BY CRM1.id DESC"

But the query returns nothing ..

Can somebody tells me what I'm doing wrong ?

Thanks in advance for your help.

Delrius Euphoria
  • 14,910
  • 3
  • 15
  • 46
Nico44044
  • 125
  • 8
  • Is each table really related via the primary key? That seems unlikely. If each table is structured the same, you could use a UNION structure. Otherwise, I think you will need to provide more details on the structure of each CRM* – ComplexityAverse Jan 06 '21 at 19:44
  • Does this answer your question? [SQL query return data from multiple tables](https://stackoverflow.com/questions/12475850/sql-query-return-data-from-multiple-tables) – Umair Mubeen Jan 06 '21 at 19:44

0 Answers0