Nigel12 Posted November 18, 2019 Share Posted November 18, 2019 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 Quote Link to comment https://forums.phpfreaks.com/topic/309545-mysql-using-multiple-where/ Share on other sites More sharing options...
Barand Posted November 18, 2019 Share Posted November 18, 2019 Your WHERE clause will then be like this... … WHERE id = N AND duplicate = 'False' 6 minutes ago, Nigel12 said: I'm using VB.NET You have my sympathy. Also those "Answer_x" columns should ne normalized into a separate table; separate row for each answer. Quote Link to comment https://forums.phpfreaks.com/topic/309545-mysql-using-multiple-where/#findComment-1571684 Share on other sites More sharing options...
Nigel12 Posted November 21, 2019 Author Share Posted November 21, 2019 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 .) Quote Link to comment https://forums.phpfreaks.com/topic/309545-mysql-using-multiple-where/#findComment-1571793 Share on other sites More sharing options...
Nigel12 Posted November 21, 2019 Author Share Posted November 21, 2019 Hi, so I have just tried this Query = "select Question from Questions where DuplicateCol= 'False' AND id='" + RandomN.Text + "'" it appears to work I will put it in to my main work and see what happens. But none the less Barand, Thankyou Quote Link to comment https://forums.phpfreaks.com/topic/309545-mysql-using-multiple-where/#findComment-1571794 Share on other sites More sharing options...
Psycho Posted November 22, 2019 Share Posted November 22, 2019 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. Quote Link to comment https://forums.phpfreaks.com/topic/309545-mysql-using-multiple-where/#findComment-1571804 Share on other sites More sharing options...
Nigel12 Posted November 23, 2019 Author Share Posted November 23, 2019 (edited) 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 November 23, 2019 by Nigel12 Quote Link to comment https://forums.phpfreaks.com/topic/309545-mysql-using-multiple-where/#findComment-1571819 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.