Hello fellow programmers,
to describe my problem a bit better:
I've got 2 tables with a lot of columns. They have some of coloumns in common.
Table 1 is the Customer table with Customer ID, First Name, Last Name, Company, Street, Zipcode, City, category and others.
Table 2 is the Bookings table has First Name, Last Name, Company, Street, Zipcode and City, too. Table 2 has additionaly the Coloums Room_ID, Date, Customer_ID and others. Stupid thing is: The Customer_ID is empty at some entries.
Now I have to get the data of every Person from Costumer table that booked a room.
After some reasearch and after reading trough http://www.codeproject.com/Articles/33052/Visual-Representation-of-SQL-Joins and How to do an INNER JOIN on multiple columns I think that I need an Inner Join for this.
My problem is that the approach recommended in How to do an INNER JOIN on multiple columns doesn't reaaly fit to what I need, since I whant to join on 2 coloumns and not 2 times on the same soloumn.
This is my query so far:
'SELECT tbl1.ID, tbl1.company, tbl1.title, tbl1.lastname, tbl1.fistname, tbl1.street, tbl1.city, tbl1.zipcode, tbl1.phone, tbl1.email, tbl1.category_ID, tbl1.Hotel_ID, tbl2.*
FROM customer AS tbl1
INNER JOIN booking AS tbl2
ON
WHERE '.$searchterms.'
GROUP BY tbl1.firstname, tbl1.lastname, tbl2.room, tbl2.date'
here is some pseudo-code of the way the join should look like:
'Select needed cloumns
FROM customer AS tbl1
INNER JOIN booking AS tbl2
ON tbl1.firstname=tbl2.firstname AND tbl1.lastname=tbl2.lastname
WHERE '.$searchterms.'
GROUP BY tbl1.firstname, tbl1.lastname, tbl2.room, tbl2.date'
What I need is a hint, an explantion or a link that helps me to come up with a solution and I'd be very thankfull. I've got some kind of blackout regarding explained problem. I hope that you can help me.