Assume I want to write the following SQL Query:
SELECT Employee.Name, Employee.ID, InvitedToParty.Name, InvitedToParty.FavoriteFood
FROM Employee, InvitedToParty
WHERE Employee.ID = InvitedToParty.ID
given the required tables :
Employee
ID Name Birthday
1 Heiny 01.01.2000
2 Peter 10.10.1990
3 Sabrina 12.10. 2015
.
.
InvitedToParty
Name FavoriteFood
Michael Pizza
Heiny Pizza
Sabrina Burger
George Pasta
.
.
.
Assume I have this information as two lists in Python inside a dictionary:
tables['Employee'].id = [1, 2, 3 ..]
tables['Employee'].Name = [Heiny, Peter, Sabrina ...]
I hope you get the idea. These keys of the dictionary have attributes, because I created a class for each table.
How can I write this query in Python? My initial idea was (pseudo):
match_counter = 0
for i, value in enumerate(table1.column):
for j in range(len(table2.column)):
if table2.column[j] == value:
table2.column[j], table2.column[i] = table2.column[i], table2.column[]
match_counter += 1
And remove everything after 'match_counter'
rows. But I am sure there must be a better way? Moreover, I do not even know if this would give me the correct result
source https://stackoverflow.com/questions/72720903/hash-join-algorithm-from-mysql-in-python
Comments
Post a Comment