B4J Question how combine two sql query

Discussion in 'B4J Questions' started by behnam_tr, Aug 18, 2019.

  1. behnam_tr

    behnam_tr Member

    hi

    i want to combine two sql query

    Code:
    Dim RS As ResultSet=Sql1.ExecQuery2("SELECT * FROM tbl WHERE userid = ? "Array As Int(uid))
        
    Dim RS As ResultSet=Sql1.ExecQuery2("SELECT * FROM tbl OFFSET LIMIT ?,?",Array As String(0,10))
    how do i this ??
     
  2. jmon

    jmon Well-Known Member Licensed User

    I guess with UNION?:
    http://www.mysqltutorial.org/sql-union-mysql.aspx

    Code:
    Dim s As String = $"
    SELECT * FROM tbl WHERE userid = ?
    UNION
    SELECT * FROM tbl OFFSET LIMIT ?,?"$

    Dim RS As ResultSet=Sql1.ExecQuery2(s, Array (uid, 0,10))
     
    behnam_tr likes this.
  3. behnam_tr

    behnam_tr Member

    thanks i check this
    i mean i want select 10records where userid=x from tbl
     
  4. jmon

    jmon Well-Known Member Licensed User

    How about that? That selects 10 rows where the column userid = uid
    Code:
    Dim s As String = $"
    SELECT * FROM tbl WHERE userid = ? LIMIT ?;"$

    Dim RS As ResultSet=Sql1.ExecQuery2(s, Array (uid,10))
     
    behnam_tr likes this.
  5. behnam_tr

    behnam_tr Member

    i check this but it select all rows

    Code:
    Dim s As String = $"
    SELECT * FROM hesabdari WHERE userid = ?
    UNION
    SELECT * FROM hesabdari OFFSET LIMIT ?,?"$

        
    Dim RS As ResultSet=Sql1.ExecQuery2(s, Array (uid, counter,19))
    first shuold i select all row where uid=x
    then i want to select 0-10 rows or x-y row from rows that fetched from first step
    maybe first step return 50 rows i want select 0-10 records or 10-20 records (start pos- end pos)
    ok ??
     
    Last edited: Aug 19, 2019
  6. DonManfred

    DonManfred Expert Licensed User

    why two sql then for this if it can be done with ONE simple SQL like @jmon suggested in #4
     
  7. DonManfred

    DonManfred Expert Licensed User

    use LIMIT

    LIMIT 0,10 (0 to 9)
    LIMIT 9,5 (10 to 15)

    something like
    Code:
    Dim s As String = $"
    SELECT * FROM tbl WHERE uid = ? LIMIT ?,?;"$

    Dim RS As ResultSet=Sql1.ExecQuery2(s, Array (uid,9,5))
    I strongly suggest to learn the SQL Language basics.
     
    Erel and jmon like this.
  8. behnam_tr

    behnam_tr Member


    thanks guys
    solved with this ;););)
     
    jmon likes this.
Loading...
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice