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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T14:24:57+00:00 2026-06-09T14:24:57+00:00

I have the DB below and when I try to run an SQL command

  • 0

I have the DB below and when I try to run an SQL command it doesn’t do quite what it should do (the code below should have a cursorSize of 1 but it shows 0).

The code I run is:

SQLiteDatabase db = this.getReadableDatabase();

String countQuery = "SELECT  songid FROM TABLE_TRACKS WHERE (tagid = 7 OR tagid = 10) AND tagid = 9";
Cursor cursor = db.rawQuery(countQuery, null);
int cursorSize = cursor.getCount();

Its something to do with the where clause, because when I change the brackets and make it

WHERE (tagid=9 AND tagid = 7) OR tagid=10

It works because int cursorSize is 2.
Is there something silly I am missing out or something I don’t know about SQL WHERE clause or AND/OR operators?

Would really appreciate if someone could explain this for me and how to get the results that I want. (Below I want to return one row with songid equal to 3.)

enter image description here

  • 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-09T14:24:58+00:00Added an answer on June 9, 2026 at 2:24 pm

    Ther is nothing wrong with the result. It should give you zero because:

    • There is no way that you have a row where the tagid = 7 and 9 at the same time.
    • There is no way that you have a row where the tagid = 10 and 9 at the same time.

    You need to check your app logic and what are you trying to accomplish here.

    Edit:

    So think of songIDs as songs and tagIDs as Tags (guitar, piano, romantic and so on) so if I want to find the songs which has (piano AND guitar) OR romantic tag how is it possible ? do I have to change my db (table) or can I reformulate my sql ?

    If this is the context of your app, and you expect some input combinations from the users, I suggest you change your db scheme. try to add Boolean columns for each tag. This will be easier in case you are expecting such combinations and it will not differ that much in terms of space.

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

Sidebar

Related Questions

I am trying to run this code below while learning the java sql stuff,
I have used the code below to read rfid tag values. try { if
I try to run ELMAH with my ASP.NET MVC 2 project but have some
I have the code below to query records from a stored procedure but am
I'm reading an article from this website , but when i run the code
I have the following script below where I try to mimic a file upload
I have below snippet of code in which TestClass is extending jPanel which is
I have below code: <a href=# id=@item.Id name=vote ><img src=/Content/images/021.png style=float:left alt= /></a> which
I have below code: class Program { static void Main(string[] args) { Task[] tasks
I have below html code in my aspx. <input type=hidden id=medicalLink value='<a href=/forms/contactus.aspx >Contact

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.