Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7970595
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T07:25:38+00:00 2026-06-04T07:25:38+00:00

I have a small problem regarding a count after grouping some elements from a

  • 0

I have a small problem regarding a count after grouping some elements from a mysql table,
I have an orders table .. in which each order has several rows grouped by a code (named as codcomanda) … I have to do a query which counts the number of orders per customer and lists only the name and number of orders.

This is what i came up (this might be dumb … i’m not a pro programmer)

SELECT a.nume, a.tel, (
    SELECT COUNT(*) AS `count` 
      FROM (
        SELECT id AS `lwtemp` 
          FROM lw_comenzi_confirmate AS yt 
         WHERE status=1 AND yt.tel LIKE **a.tel** 
         GROUP BY yt.codcomanda
      ) AS b
  ) AS numar_comenzi 
  FROM lw_comenzi_confirmate AS a 
 WHERE status=1 
 GROUP BY tel;

nume = NAME
tel = PHONE (which is the distinct identifier for clients since there’s no login system)

The problem with the above query is that I don’t know how to match the a.tel with the one on which the first select is on. If I replace it with a number that is in the db it works….

Can anyone help me one how to refer to that var?
or maybe another solution on how to get this done?

If any more info is needed I`ll provide asap.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-04T07:25:40+00:00Added an answer on June 4, 2026 at 7:25 am

    Please, correct me if I’m wrong in my understanding of your schema:

    • lw_comenzi_confirmate contains nume and tel of the customer;
    • lw_comenzi_confirmate contains order details (same table);
    • one order can have several entries in the lw_comenzi_confirmate table, order is distinguished by codcomanda field.

    First, I highly recommend reading about Normalisation and fixing your database design.

    The following should do the job for you:

    SELECT nume, tel, count(DISTINCT codcomanda) AS cnt
      FROM lw_comenzi_confirmate
     WHERE status = 1
     GROUP BY nume, tel
     ORDER BY nume, tel;
    

    You can test this query on SQL Fiddle.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a small wordpress & css related problem regarding some elements that are
I have a little problem regarding arranging of code, which depends on each other
I have one small problem regarding MPMoviePlayerController, i have a link that play movie
i have a small problem regarding jquery/php. in the last few days i built
have small problem, and would very much appreciate help :) I should convert byte
I have a small problem with Smarty... I have two different template files in
I have a small problem where I want to find the next active item
i have a small problem, i am creating a edit page in my asp.net
I have a small problem with a SWT.Browser widget who throws a quite puzzling
I have a small problem... There are hundreds of images in a folder. they

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.