Jump to content

MySql using multiple WHERE


Recommended Posts

Hi, I have a MySql query which currently looks like this

Query = "select Question,Answer1,Answer2,Answer3,CorrectAnswer,id,Duplicate from Questions where id='" + RandomN.Text + "'"
As you can see I have a table called 'Questions' which has several columns, Im using VB.NET I also have a textBox on a windows form called 'RandomN'
What this does is it takes whatever number is in my textBox called RandomN.Text and looks for that number in the id column and returns all data on that row.

What I am trying to acheive now is this, I have a column called Duplicate it will either contain the word 'True' or 'False' I would like it to only return data from the given number in the textBox if the Duplicate column in that row contains the word 'False'

If someone can shed some light I would be greatful. Thanks

Link to comment
Share on other sites

Hi Barand, thanks for the answer, but it throws problems back at me. So I created a new form  and reduced the query so I could concentrate on getting it right.  On my form I have a button 1 x TextBox and 1 x Label The label will hold a random number between 1 and 45 (currentlty holding the number 6) I have called the label 'RandomN'  The TextBox is simply called 'TextBox2'

My original query was


Query = "select Question,Answer1,Answer2,Answer3,CorrectAnswer,id,Duplicate from Questions where id='" + RandomN.Text + "'"

I looked at what your answer said and came up with this one below.

Query = "select Question from Questions where id= 'RandomN.Text' AND DuplicateCol= '" + False + "'"

The error  I get is  Conversion form string 'select Question form Questions w'  to type 'Double is not valid


Now if I am simply selecting from one column its easy right. lol

Query = "select Question from Questions where DuplicateCol= 'False'"


Anyway my next attempt was

Query = "select Question from Questions where DuplicateCol= 'False' AND id'" + RandomN.Text() + "'"

But this one just throws me an error telling me I have an error with my Sql syntax near 6 at line 1

As for the VB.NET dig I dont need your sympathy I am getting round to learning other things. Im just to busy, in fact im the busiest person I know. Im fairly confident most would fall apart at my work load .)

Link to comment
Share on other sites

20 hours ago, Psycho said:

Do you understand WHY that last attempt worked and the previous ones failed? If not, you are going to repeat the same errors in the future.

Hi Phycho, So I can now confirm that it did work, and this would be a great opportunity for you to jump in and give a detailed explanation. I look forward to reading it, I have been following tutorials on w3schools which is good. But I enjoy putting them in to practice which quite often throws errors back. Thats when Forums like this become there weight in gold. in in the meantime im already working on my next thread 😉

Edited by Nigel12
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.