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 8381389
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T16:41:17+00:00 2026-06-09T16:41:17+00:00

I hope the question is clear enough. Here’s my query: SELECT ‘Total Complete’ AS

  • 0

I hope the question is clear enough.

Here’s my query:

SELECT
    'Total Complete' AS name, count(c.id) AS amnt
FROM
    lanes AS c
      LEFT JOIN leads AS l
        ON ((c.carrier_mcn = l.authority_number
              AND l.authority_type = 'mc')
          OR c.carrier_mcn = l.mcn
          OR c.carrier_mcn = CONCAT('MC', l.authority_number))
          AND c.carrier_mcn <> 0
  LEFT JOIN lanes_emails AS cem1
    ON cem1.cid = c.id AND cem1.deleted = 0
  LEFT JOIN lanes_emails AS cem2
    ON cem1.cid = cem2.cid AND cem2.deleted = 0 AND cem2.id < cem1.id
  LEFT JOIN lanes_equipment AS ceq1
    ON ceq1.cid = c.id AND ceq1.deleted = 0
  LEFT JOIN lanes_equipment AS ceq2
    ON ceq1.cid = ceq2.cid AND ceq1.deleted = 0 AND ceq2.id < ceq1.id
  LEFT JOIN lanes_service_area AS csa1
    ON csa1.cid = c.id AND AND flag = 2 csa1.deleted = 0
  LEFT JOIN lanes_service_area AS csa2
    ON csa1.cid = csa2.cid AND AND flag = 2 csa1.deleted = 0 AND csa2.id < csa1.id
WHERE
    c.carrier_mcn IS NOT NULL and c.carrier_mcn <> ''
    AND c.broker_mcn IS NOT NULL and c.broker_mcn <> ''
    AND c.fax IS NOT NULL and c.fax <> ''
    AND cem2.id IS NOT NULL
    AND ceq2.id IS NOT NULL
    AND csa2.id IS NOT NULL

Now what I’m trying to do here is get the total count of rows from “lanes” where it has at least one email, equipment, service area, mc number, or fax number. There are two MC Numbers, but they’re both on the same table; the main issue is that there can be unlimited emails, equipment, and service areas.

In this case, I starting writing out an article about this issue and discovered another similar problem:

MySQL: Can I do a left join and pull only one row from the join table?

So I tried it out and implemented it into my query. Unfortunately, it didn’t work the way I had planned.

It would work fine if I had more than one row; it would get the correct count, ignoring the fact that I had multiple emails or whatnot, but it would NOT work if there was only one. Instead, it returned no results.

No, I cannot use GROUP BY to get the results I need; I’ve tried GROUP BY, I love using it when returning full result lists, but if I’m trying to return counts GROUP BY repeatedly messes me up.

Is there any way to force a join in mysql to return just one row without using a subquery? I only need to know if there is one item from any of these other tables, I don’t need to return everything, and I don’t know of a way to program it to work through the WHERE clause.

I need this query for a bar chart. I’ve actually got several of these queries; this one is the one that requires all results, but I have others for no requirements, at least one email, at least one mc number, etc., but if I can get this working I can get the rest working.

  • 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-09T16:41:18+00:00Added an answer on June 9, 2026 at 4:41 pm

    You could use an exists clause:

    where   exists 
            (
            select  *
            from    lanes_emails AS cem1
            where   cem1.cid = c.id 
                    and cem1.deleted = 0
            )
            and exists
            ...
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

this is my first question here; hope I'll be clear enough... I've got this
I hope I can make this question clear enough. I'm looking to put a
I hope my question will be clear and perfect enough to not get down
Hopefully the title of my question was clear enough. Here's a really simple version
The question is clear, I hope. I have the body of the DOM (which
This is my first question on Stack Overflow, so I hope that I'm clear
This is my first question in this forum, so i hope to be clear:
I try again to ask my question. I hope that this time it's clear
try{ String query= select user_name from user; ResultSet rs = queries.performQuery(query); while(rs.next()){ System.out.println(User Name
Hope this question is not stupid since I am an amateur web designer. I

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.