2

I have a table name "a"

 Id   name
 1    abc
 2    xyz
 3    mmm
 4    xxx

and Other table name is "b"

  Id    suId
   3     2
   3     1

My requirement is get detail from "a" table from "b" table where id=3. Any help?

2
  • what is the expected output? Commented Feb 28, 2014 at 6:46
  • from B where Id=3 get information about all suId into table "a" Commented Feb 28, 2014 at 6:48

5 Answers 5

1
SELECT a.Id, a.name, b.Id, b.suId FROM b JOIN a ON b.suId = a.Id WHERE b.Id = 3;
Sign up to request clarification or add additional context in comments.

Comments

1

I wont recommend join for this kind of scenarios(you want all details from Table A whose ids are in Table B suId column, where Table B id should be 3., Its bad English but hope you got me and may be i got you too.)

SELECT a.name FROM a
WHERE 
a.id IN(SELECT b.suId FROM b WHERE b.id = 3);

If you want to use join only then,

SELECT a.name FROM a,b
WHERE a.id = b.suId
AND
b.id = 3;

Comments

0

Simple answer:

SELECT a.Id,a.name FROM a,b
WHERE a.Id=b.suId AND b.Id=3

It will give you the result:

Id    Name
1     abc
2     xyz

See result in SQL Fiddle

Comments

0

This should get the job done:

SELECT * FROM table_a a JOIN table_b b ON b.suId = a.Id WHERE b.Id = 3;

Comments

0

You can try this...You can try different JOIN clauses like INNER JOIN, LEFT OUTER JOIN or just simply JOIN etc. You will get different number of rows depending on field connections from 1 table to the other.

SELECT T1.*
FROM a T1
INNER JOIN b T2
ON T1.Id = T2.Id
WHERE T1.Id='3'

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.