Search code examples
mysql.netdatabaseexecutereader

Query between two tables


This is my query with 2 parameters. Can someone please help me?

sql = "select * 
       from studentlist 
       where firstname like '%" 
     & Transaction.SEARCHSTUDENT.Text 
     & "%' or studentnum like '%" 
     & Transaction.SEARCHSTUDENT.Text 
     & "%' and not in (select studentnum from borrowing of books where status ='borrowed')"

Solution

  • If borrowing of books is your table name (with whitespaces) it should be enclosed with backticks like so:

    `borrowing of books`
    

    Edit: Also, it looks like studentnum is missing in your where clause, so it should actually look like this:

    sql = "select * 
       from studentlist 
       where (firstname like '%" 
     & Transaction.SEARCHSTUDENT.Text 
     & "%' or studentnum like '%" 
     & Transaction.SEARCHSTUDENT.Text 
     & "%') and studentnum not in (select studentnum from `borrowing of books` where status ='borrowed')"