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

  • Home
  • SEARCH
  • 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 3696344
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T04:43:40+00:00 2026-05-19T04:43:40+00:00

Hello I have got the problem with my query and it display the correct

  • 0

Hello I have got the problem with my query and it display the correct data but not correct amount (count (*)). Somehow it should display the data as 1 for that part but it display 4.
I don’t know where is the error is.

select Vehical_Type, 
       Vehical_Registration_No, 
       count(*) 
from van, 
     van_booking 
where Vehical_Type = 'Ford - Transit' 
  and Vehical_Registration_No <> fk2_Vehical_Registration_No 
         not in (select fk2_Vehical_Registration_No 
                 from van_booking 
                 where '2010.10.12' between Hire_Start_Date and Hire_End_Date 
                    or '2010.10.11' between Hire_Start_Date and Hire_End_Date);

Please can anyone help me?

  • 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-05-19T04:43:41+00:00Added an answer on May 19, 2026 at 4:43 am

    Where do we start?

    select Vehical_Type, Vehical_Registration_No, count(*)
    from van, van_booking
    where Vehical_Type = 'Ford - Transit'
      and Vehical_Registration_No <> fk2_Vehical_Registration_No
    **not in (**
      select fk2_Vehical_Registration_No
      from van_booking
      where '2010.10.12' between Hire_Start_Date and Hire_End_Date
         or '2010.10.11' between Hire_Start_Date and Hire_End_Date);
    

    Since there is no “AND ” before the NOT IN, so

    1. there is no context as to whether it should be right or wrong
    2. the query won’t even run

    At least try to post a working query since you seem to indicate it works (and returns count=>4).

    Secondly, please alias the table names so that you can prefix the columns with the alias names. At present, it is ambiguous as to which columns belong to which tables.

    Thirdly, I guess this is MySQL? You should always state which DBMS you are working with, but MySQL is the only one that will let you get away with MIXING aggregate and non-aggregate fields WITHOUT a GROUP BY clause.

    Fourthly, please try to learn to use SQL92 ANSI joins instead of the old-style cross-join and filter-in-WHERE. It looks like you have crossed Van and Van_Booking tables without any correlation clause. What are you trying to achieve?

    Lastly, and this ties to the last point, it would greatly help to list out some sample data rows and what the result should look like based on that sample data.

    I am going to guess that what you are actually after is a list of vehicle registration numbers of the type requested, but at the same time, in the COUNT column, show… the total number of records matching the query? So, something like this?

    Type | Registration | Count
    Ford - Transit | ABC123 | 4
    Ford - Transit | D4 | 4
    Ford - Transit | XY13 | 4
    Ford - Transit | PQS333 | 4
    

    It’s just a guess, but without the count, you can use this

    select Vehical_Type, Vehical_Registration_No
    from van
    where Vehical_Type = 'Ford - Transit'
      and Vehical_Registration_No not in (
      select fk2_Vehical_Registration_No
      from van_booking
      where '2010.10.12' between Hire_Start_Date and Hire_End_Date
         or '2010.10.11' between Hire_Start_Date and Hire_End_Date);
    

    To include the count (which would be the same value in all rows), you can duplicate the query as a subquery to itself

    select Vehical_Type, Vehical_Registration_No, C.C
    from van
    cross join (
        select COUNT(*) C
        from van
        where Vehical_Type = 'Ford - Transit'
          and Vehical_Registration_No not in (
          select fk2_Vehical_Registration_No
          from van_booking
          where '2010.10.12' between Hire_Start_Date and Hire_End_Date
             or '2010.10.11' between Hire_Start_Date and Hire_End_Date)) C
    where Vehical_Type = 'Ford - Transit'
      and Vehical_Registration_No not in (
      select fk2_Vehical_Registration_No
      from van_booking
      where '2010.10.12' between Hire_Start_Date and Hire_End_Date
         or '2010.10.11' between Hire_Start_Date and Hire_End_Date);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Imagine I have the following: inFile = /adda/adas/sdas/hello.txt # that instruction give me hello.txt
If I have data in the following format id subid text 1 1 Hello
I have got a problem when I try to make following simple connections QSpinBox
hello i got a problem with reading from a file, i am trying to
Hello I have the following error by git-fsck, which cannot be cleaned by git-gc
Hello we have an SQL server application running over a low bandwith connection. We
Hello I have a number of crystal reports in my VS2008 project. I am
I have done this: $ z() { echo 'hello world'; } How do I
Say for example I have the following string: var testString = Hello, world; And
I have a file called hellowf.cs class MyFirstApp { static void Main() { System.Windows.Forms.MessageBox.Show(Hello,

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.