2 Replies Latest reply: Jun 6, 2014 11:45 AM by Frank Kulash RSS

    Sql statement with join and where condition

    14698fc7-faf7-45f3-bf31-41b097cbc1da

      Hello,

       

      I am new the world of SQL and have basic understanding of writing simple queries.  I am tring to join data from several tables and have been sucessful at doing so, however for one table I need to apply a Where condition so only particular data is joined.  Question is how can I incorporate a Where column = 12 in a statement that has multiple joins.

       

      Thanks.

        • 1. Re: Sql statement with join and where condition
          KayK

          Hi,

          welcome to community.

          You have a select with join clauses, right ? Or do you join manually in a where clause ?

          Simply add your condition in the where clause. The table from which you column comes has an alias i think, so just do


               where <alias or table_name>.column = 12

           

          That's all.

          Or post your complete query then we see how to help you.

           

          regards
          Kay

          btw please choose a more readable name for your avatar. Thanks

          • 2. Re: Sql statement with join and where condition
            Frank Kulash

            Hi,

             

            Whenever you have a problem, please post a little sample data (CREATE TABLE and INSERT statements, relevant columns only) from all tables involved, so that the people who want to help you can re-create the problem and test their ideas.

            Also post the results you want from that data, and an explanation of how you get those results from that data, with specific examples.

            Simplify the problem as much as possible.  If you need to join several tables, but the part you don't know how to do can be shown using only 2 tables, then post a problem using only those 2 tables.

            Always say which version of Oracle you're using (for example, 11.2.0.2.0).

            See the forum FAQ: https://forums.oracle.com/message/9362002#9362002

             

            If all the joins are inner joins, then you can just put that condition in the WHERE clause.  (Add a WHERE clause immediately after the FROM clause if there isn't already a WHERE clause.)

            If some of the joins are outer joins, you might need to put that condition in the join conditions.  It depends on your data and your requirements.