mysql - multiple where and search

Posted by Shamil on Stack Overflow See other posts from Stack Overflow or by Shamil
Published on 2012-11-06T22:17:03Z Indexed on 2012/11/06 23:00 UTC
Read the original article Hit count: 157

Filed under:

I'm trying to write a SQL query that satisfies multiple criteria.

Of these, most are connected via a column, so joins are possible, however, some queries are such that I'd have to search additional tables for the information. What would be the least expensive and best way to do this?

Let's say that we have a few tables.

One table contains information such as sales information for a server: the salesperson, client id, service lease term, timestamps etc. It is possible that a client has multiple sales but with a different "service". I'd need to pick up all of the different ones.

Another table has the quotes for the services, I'd need to pick some information out about this, whilst another, which could be joined to this one has some more information.

Those tables are linked by a common client ID, so joins are possible, but I'd also need to search the first table for multiple instances of the client ID. Of course, I'd want to restrict the search to certain timestamps, which I can easily do as the timestamps are stored in MySQL format.

© Stack Overflow or respective owner

Related posts about mysql