MySQL newb question...

Do you have a question? Post it now! No Registration Necessary.  Now with pictures!

Threaded View
Hey, I am working on a app that lets employees in my business create
printable sales estimates. I am looking to make it possible to enter
as many items as needed for the estimate. lvaro G. Vicario's
suggestion in another post prompted me to form two of my tables as

estimates: estID, userName, custID, date
items: itemID, estID, description, model, sku, price, qty

The problem I am having (mostly thanks to my lack of sql experience)
is the actual query that would be used on the page that lists all of
the specific user's estimates, showing one estimate per line, each
with the description of the first item (along with more info about the

So far my query is as follows:

SELECT estimates.estID, estimates.userName, estimates.custID,, customers.custName, items.estID, items.itemID,
FROM estimates, customers, items
WHERE estimates.userName = '(session userID)' AND customers.custID =
estimates.custID AND items.estID = estimates.estID

This seems to be close to what I want, but I don't know how to specify
that I want to only display one item from each estimate (right now
this query would display each estimate, and every item from them).

Any suggestions on how to write a good query for this?

I hope I am clear in my question, and thanks for any help you may

Re: MySQL newb question...

transpar3nt wrote:
Quoted text here. Click to load it

Some here will point out that this is a php newsgroup , and will in this
case be correct.

I know lots about php but I'm not an expert however. I know even less
about mysql. I know enough to know that  your sql _looks_ valid.

But you already said that it works . I know you can add a limit 1 on the
end of that string and get only one result . But i am not sure if that
is what your after ,you should really go ask a mysql based group to
make sure you get a related solution.

Although you may grab a number of entries, via a sql request ,it doesn't
mean you  HAVE to use all of them nor all the data when outputting a result.

For us to really comment on your question I suggest that when posting to
   a php newsgroup that you post your php source.

Sorry I know I haven't been much help


Re: MySQL newb question...

I appreciate your responses, and yeah I know it's a PHP group.  I only
asked it here because I have had such great luck with the people who
answer here.  I'll go to the MySQL group for an answer.

Re: MySQL newb question...

transpar3nt wrote:
Quoted text here. Click to load it

Yes, you have a sql question, so you should be asking in a sql
newsgroup.  For instance, if you're using MySQL, try comp.databases.mysql.

Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.

Re: MySQL newb question...

Jerry Stuckle wrote:
Quoted text here. Click to load it

   I'm not so sure that it can be answered in plain sql. I *think* what
his problem is that he is retrieving several estimates for each
customer's item. He is printing out all of that so that he is getting
the customer info for every estimate that belongs to that customer. What
he wants is the customer/ incident info printed just once and then the
estimates that belong to that incident. Whew...

  So, although this appears to be an sql issue, it is not. It's not a
php issue either, but one of programming style.

You can stop reading now Jerry...

   There's a few ways to deal with this. You can order by
customer,estimate. (whatever needs to be sorted)

One way is to save the customer in a variable and then print again if it


    if($customer_saved != $row['customer']){
        echo $row['customer'];
... the rest of what needs to be done
    $customer_saved = $row['customer'];

   There's other ways of doing this, and it *may* be possible in just
sql, but I wouldn't know how. Sometimes a little programming logic can
make the sql very simple.


Quoted text here. Click to load it

Re: MySQL newb question...

Jeff wrote:
Quoted text here. Click to load it

Jeff, your first clue should be the subject: "MySQL newb question".
Nothing in this has anything to do with PHP.

And yes, the query can be done in SQL.

Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.

Site Timeline