I'm creating a search function for my program, and need some help with SQL. Until now I have been using simple SQL query like

"SELECT post1 FROW table1 WHERE a=b"

and put it into arrays. Then using that info to do another query, put it into arrays, and so on.

I know there are ways to improve my SQL querys like this

"SELECT table1.post1, table2.post2 FROM table1, table2 WHERE a=b"

(more or less)

I want to query (using JOIN?) 3 tables, where some of the posts are only intermediate data to find posts in other tables.

Table 1:

Table 2:

Table 3:


I have the UserName, and from that I need to get the UserID to get to the latest Date and corresponding CustomerID. Then use the CustomerID to get the Order.
All UserName has 3 UserID (Only one are in use at any given time).
All Dates has between 1 and 500 CustomerID
All CustomerID has 1 Order

Try this:

SELECT t2.date, t3.order FROM Table1 As t1 JOIN Table2 AS t2 JOIN Table3 AS t3 ON t1.userID = t2.userID AND t2.customerID = t3.customerID WHERE t1.userName = 'name';

Use the JOIN and ON statements to connect tables by the columns they have in common (userID for tables 1 and 2, customerID for tables 2 and 3).
Hope that helps.