locked
SQL Query No Data Appear RRS feed

  • Question

  • User1109811461 posted

    hai all expertise

    just now i'm creating new database , what happen is that what i make a query then there are no data appear i need help regading this matters, i'm new in this.

    below is my table field

    SELECT TOP 1000 [IdKenderaan]
          ,[IdKakitangan]
          ,[NoKenderaan]
          ,[JenisKenderaan]
          ,[WarnaKenderaan]
          ,[Selenggara]
          ,[TarikhSelenggara]
          ,[TarikhSelengeraNext]
      FROM [BookingSystem].[dbo].[MaklumatKenderaan]

    SELECT TOP 1000 [IdPerjalanan]
          ,[IdKakitangan]
          ,[IdKenderaan]
          ,[TujuanPerjalanan]
          ,[TarikhGuna]
          ,[TarikhTamat]
          ,[MasaGuna]
          ,[MasaTamat]
          ,[Destinasi]
          ,[JumlahPenumpang]
      FROM [BookingSystem].[dbo].[MaklumatPerjalanan]

    below this is my query

    SELECT     MaklumatKenderaan.NoKenderaan, MaklumatKenderaan.JenisKenderaan, MaklumatPerjalanan.TujuanPerjalanan, MaklumatPerjalanan.TarikhGuna,
                          MaklumatPerjalanan.TarikhTamat, MaklumatPerjalanan.MasaGuna, MaklumatPerjalanan.MasaTamat, MaklumatPerjalanan.Destinasi,
                          MaklumatPerjalanan.JumlahPenumpang
    FROM         MaklumatKenderaan INNER JOIN
                          MaklumatPerjalanan ON MaklumatKenderaan.IdKenderaan = MaklumatPerjalanan.IdKenderaan

    Friday, February 1, 2013 3:35 AM

Answers

  • User477186420 posted

    your query is look ok, you need to verify the data

    weather  value of "[IdKenderaan]" in "[MaklumatKenderaan]" is availabe in "[IdKenderaan]" of table [MaklumatPerjalanan]

    your query only returns thoes record which have common "[IdKenderaan]" value

    let me know if any query

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Friday, February 1, 2013 4:44 AM
  • User226262986 posted

    If you want to return query which is in left table whether right table is blank then use Left outer join in place of Inner Join

    If you want to return query which is in right table whether left table is blank then use Right outer join in place of Inner Join

    like

    SELECT     MaklumatKenderaan.NoKenderaan, MaklumatKenderaan.JenisKenderaan, MaklumatPerjalanan.TujuanPerjalanan, MaklumatPerjalanan.TarikhGuna, 
                          MaklumatPerjalanan.TarikhTamat, MaklumatPerjalanan.MasaGuna, MaklumatPerjalanan.MasaTamat, MaklumatPerjalanan.Destinasi, 
                          MaklumatPerjalanan.JumlahPenumpang
    FROM         MaklumatKenderaan LEFT OUTER JOIN
                          MaklumatPerjalanan ON MaklumatKenderaan.IdKenderaan = MaklumatPerjalanan.IdKenderaan

    OR

    SELECT     MaklumatKenderaan.NoKenderaan, MaklumatKenderaan.JenisKenderaan, MaklumatPerjalanan.TujuanPerjalanan, MaklumatPerjalanan.TarikhGuna, 
                          MaklumatPerjalanan.TarikhTamat, MaklumatPerjalanan.MasaGuna, MaklumatPerjalanan.MasaTamat, MaklumatPerjalanan.Destinasi, 
                          MaklumatPerjalanan.JumlahPenumpang
    FROM         MaklumatKenderaan RIGHT OUTER JOIN
                          MaklumatPerjalanan ON MaklumatKenderaan.IdKenderaan = MaklumatPerjalanan.IdKenderaan



    YOUR QUERY WILL return those records which are common in both tables else not returning any row.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Friday, February 1, 2013 4:55 AM

All replies

  • User477186420 posted

    your query is look ok, you need to verify the data

    weather  value of "[IdKenderaan]" in "[MaklumatKenderaan]" is availabe in "[IdKenderaan]" of table [MaklumatPerjalanan]

    your query only returns thoes record which have common "[IdKenderaan]" value

    let me know if any query

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Friday, February 1, 2013 4:44 AM
  • User226262986 posted

    If you want to return query which is in left table whether right table is blank then use Left outer join in place of Inner Join

    If you want to return query which is in right table whether left table is blank then use Right outer join in place of Inner Join

    like

    SELECT     MaklumatKenderaan.NoKenderaan, MaklumatKenderaan.JenisKenderaan, MaklumatPerjalanan.TujuanPerjalanan, MaklumatPerjalanan.TarikhGuna, 
                          MaklumatPerjalanan.TarikhTamat, MaklumatPerjalanan.MasaGuna, MaklumatPerjalanan.MasaTamat, MaklumatPerjalanan.Destinasi, 
                          MaklumatPerjalanan.JumlahPenumpang
    FROM         MaklumatKenderaan LEFT OUTER JOIN
                          MaklumatPerjalanan ON MaklumatKenderaan.IdKenderaan = MaklumatPerjalanan.IdKenderaan

    OR

    SELECT     MaklumatKenderaan.NoKenderaan, MaklumatKenderaan.JenisKenderaan, MaklumatPerjalanan.TujuanPerjalanan, MaklumatPerjalanan.TarikhGuna, 
                          MaklumatPerjalanan.TarikhTamat, MaklumatPerjalanan.MasaGuna, MaklumatPerjalanan.MasaTamat, MaklumatPerjalanan.Destinasi, 
                          MaklumatPerjalanan.JumlahPenumpang
    FROM         MaklumatKenderaan RIGHT OUTER JOIN
                          MaklumatPerjalanan ON MaklumatKenderaan.IdKenderaan = MaklumatPerjalanan.IdKenderaan



    YOUR QUERY WILL return those records which are common in both tables else not returning any row.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Friday, February 1, 2013 4:55 AM
  • User1109811461 posted

    hi dhol.gaurav and NadeemZee

    dhol.gaurav resolve my problem,

    NadeemZee give me some knowledge that i never notice before this...thank's a lot's to both of you expertise

    after this there are lot's of query maybe i need guidance from expertise here..:))

    Wednesday, February 6, 2013 10:22 AM