473,387 Members | 1,619 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Inner Join

6
I have two tables, table a and table b.
I do :

Expand|Select|Wrap|Line Numbers
  1. select *
  2. from a 
  3. inner join b
  4. on b.some = a.something
  5. where b.another = somevalue
How can I put another WHERE to sort my data but for an attribute from table a.
When I put it after the last WHERE it doesn't bring me any results.

Thanks
Jul 31 '07 #1
9 1846
r035198x
13,262 8TB
I have two tables, table a and table b.
I do :

select *
from a
inner join b
on b.some = a.something
where b.another = somevalue

How can I put another WHERE to sort my data but for an attribute from table a.
When I put it after the last WHERE it doesn't bring me any results.

Thanks
Can you post the query that didn't work?
You only put one where and separate the conditions with an and if you want to add additional filtering. For sorting you use order by not a where clause.
Jul 31 '07 #2
mwasif
802 Expert 512MB
Elboratingr 035198x's answer with examples

If you want to add another WHERE condition, simply add AND and the condition
Expand|Select|Wrap|Line Numbers
  1. select * from a 
  2. inner join b
  3. on b.some = a.something
  4. where b.another = somevalue
  5. AND a.comecolumn = 'some value'
This is the answer to your adding order by (sorting the results)
Expand|Select|Wrap|Line Numbers
  1. select * from a 
  2. inner join b
  3. on b.some = a.something
  4. where b.another = somevalue
  5. ORDER BY a.somecolumn
But still we want to see which query you have tried.
Jul 31 '07 #3
sade
6
Expand|Select|Wrap|Line Numbers
  1. SELECT * Person.FullName, Person.BirthDate, Person.Address 
  2. FROM Partners
  3. INNER JOIN Person 
  4. ON Person.PartnerID = Partners.Customer and Person.BirthDate > '1980-10-05' 
  5. where Partners.Producer = '158'
That's the query. If I don't use the last line (where Partners.Producer = '158'), it returns me results. But when I use a last where for any property of table Partners, the query just runs and runs... no results.
Thank you for your time.
Aug 1 '07 #4
r035198x
13,262 8TB
SELECT * Person.FullName, Person.BirthDate, Person.Address
FROM Partners
INNER JOIN Person
ON Person.PartnerID = Partners.Customer and Person.BirthDate > '1980-10-05'
where Partners.Producer = '158'

That's the query. If I don't use the last line (where Partners.Producer = '158'), it returns me results. But when I use a last where for any property of table Partners, the query just runs and runs... no results.
Thank you for your time.
I suppose you have read the responses given above?
Aug 1 '07 #5
sade
6
Thanks for your quick responses.
I am trying the way, you told me, but it doesn't work.
Maybe it's a database problem.
Aug 1 '07 #6
mwasif
802 Expert 512MB
Kinldy use appropriate code tags when posting code/syntax. Please follow this site's Posting Guidelines when posting questions or answers.
Aug 1 '07 #7
mwasif
802 Expert 512MB
You can not write the query like
Expand|Select|Wrap|Line Numbers
  1. SELECT * Person.FullName, Person.BirthDate...
You must have to use comma to separate column names in the SELECT.
Expand|Select|Wrap|Line Numbers
  1. SELECT *, Person.FullName, Person.BirthDate...
You can write your query as below too (I have moved Person.BirthDate > '1980-10-05' to WHERE clause)
Expand|Select|Wrap|Line Numbers
  1. SELECT * FROM Partners
  2. INNER JOIN Person 
  3. ON Person.PartnerID = Partners.Customer 
  4. WHERE Person.BirthDate > '1980-10-05' AND Partners.Producer = '158'
Make sure you have the records where Producer = '158' and the date is greater than '1980-10-05'.
Aug 1 '07 #8
sade
6
Because of many records I have in the database, it takes too long to bring results and most times it just crashes.
Question can be closed.
Thank you for your answers and your time.
Aug 2 '07 #9
mwasif
802 Expert 512MB
Because of many records I have in the database, it takes too long to bring results and most times it just crashes.
Consider optmizing your query by creating indexes on Person.BirthDate and Partners.Producer. This will definetly reduce your query time.
Aug 2 '07 #10

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: Ike | last post by:
Oh I have a nasty query which runs incredibly slowly. I am running MySQL 4.0.20-standard. Thus, in trying to expedite the query, I am trying to set indexes in my tables. My query requires four...
3
by: Prem | last post by:
Hi, I am having many problems with inner join. my first problem is : 1) I want to know the precedance while evaluating query with multiple joins. eg. select Employees.FirstName,...
4
by: Nathan | last post by:
I have an application that uses an Access database to gather information on students' test scores. In the database there are three tables which are joined by one- to-many relationships: ...
6
by: dmonroe | last post by:
hi group -- Im having a nested inner join problem with an Access SQl statement/Query design. Im running the query from ASP and not usng the access interface at all. Here's the tables: ...
52
by: MP | last post by:
Hi trying to begin to learn database using vb6, ado/adox, mdb format, sql (not using access...just mdb format via ado) i need to group the values of multiple fields - get their possible...
3
by: Zeff | last post by:
Hi all, I have a relational database, where all info is kept in separate tables and just the id's from those tables are stored in one central table (tblMaster)... I want to perform a query, so...
12
by: Chamnap | last post by:
Hello, everyone I have one question about the standard join and inner join, which one is faster and more reliable? Can you recommend me to use? Please, explain me... Thanks Chamnap
1
by: teneesh | last post by:
Here I have a code for a view that has been created by a developer on my team. I am trying to use the very same code to create a view for a different formid/quesid. But I cannot figure out how this...
2
by: MATTXtwo | last post by:
I have this store procedure to select data from table with join like this...SELECT tblPeribadi.Personel_No, tblPeribadi.Nama,tblCompany.Keterangan as Company_Code, tblPeribadi.Jawatan,...
4
by: AXESMI59 | last post by:
I created a query in the Access Query Builder that I modified to use with VBA Code so I could reuse it for any record I choose. The one that I created with the Access Query builder works beautifully...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.