Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
I'm learning databases and I have a question: How can I list all the students that study in a specific school using joins?
My table is as follows:
X:schoolName(PK), SchoolAddress, SchoolTelephoneNumber
Y:schoolName(FK),StudentName,StudentNumber
How can i find out all the students name that study in 'London School' including there StudentNumber, SchoolAddress?
Try this:
SELECT
Students.StudentName,
Students.StudentNumber,
Schools.SchoolAddress
FROM
XSchools
INNER JOIN YStudents
ON Schools.schoolName = Students.schoolName
WHERE Schools.schoolName = 'London School'
SELECT
StudentName,
StudentNumber,
SchoolAddress
FROM
X
JOIN Y
WHERE Y.schoolName = 'London School'
Related
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 3 years ago.
Improve this question
I am working with Yii2 and I need to use the Query Builder to convert the following raw SQL query where I am using a subquery in the inner join.
SELECT *
FROM class
INNER JOIN
(SELECT name, MAX(score) AS Maxscore
FROM class
GROUP BY name) topscore
ON class.name = topscore.name
AND class.score = topscore.maxscore;
You should show a bit of effort on your behalf as it is how it works here on SO, but as you are a new bee so i am adding an answer.
It is pretty straight forward see the Query builder guide, and you need to use the subquery in the following way
$subQuery = new \yii\db\Query();
$subQuery->select([new \yii\db\Expression('[[name]], MAX([[score]]) as Maxscore')])
->from('class')
->groupBy('[[name]]');
$query = new \yii\db\Query();
$query->select('*')
->from('class')
->innerJoin(['topscore'=>$subQuery])
->where(['=','class.[[name]]',new \yii\db\Expression('topscore.[[name]]')])
->andWhere(['=','class.[[score]]',new \yii\db\Expression('topscore.[[maxscore]]')])
->all();
Note: I didn't tested it thou but it should work correctly.
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about programming within the scope defined in the help center.
Closed 8 years ago.
Improve this question
I have 3 tables (ativo, modelo, tipo) and I need get some columns of the tables (tipo and modelo).
Structure:
Ativo: id_ativo, name_ativo, fk_tipo_atv, fk_modelo_atv
Tipo: id_tipo, name_tipo
Modelo: id_modelo, name_modelo, fk_tipo_modelo
I need list "name - name_tipo - name_modelo"
Anyone can help me?
You haven't given us much to go on regarding what results you want, how the tables are linked and what you've tried but assuming that Ativo.fk_tipo_atv is a link to Tipo.id_tipo and Ativo.fk_modelo_atv is a link to Modelo.id_modelo:
SELECT a.name_ativo,t.name_tipo,m.name_modelo
FROM Ativo a
INNER JOIN Tipo t ON (a.fk_tipo_atv = t.id_tipo)
INNER JOIN Modelo m ON (a.fk_modelo_atv = m.id_modelo)
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question appears to be off-topic because it lacks sufficient information to diagnose the problem. Describe your problem in more detail or include a minimal example in the question itself.
Closed 8 years ago.
Improve this question
Using mysql 4/5
I have 2 tables:
ROUTE
route_order (int)
zipcode
LOADS
load_id
pu_zipcode
do_zipcode
Goal:
select all rows from Loads where
pu_zipcode and do_zipcode are in Route AND
where the route_order pu_zipcode < route_order do_zipcode
I think this is what you are asking:
SELECT L.*
FROM Loads AS L
JOIN Route AS R1
ON R1.zipcode = L.PU_zipcode
JOIN Route AS R2
ON R2.zipcode = L.do_zipcode
WHERE R1.ROUTE_ORDER < R2.ROUTE_ORDER
Try this query
SELECT l.load_id, l.pu_zipcode, l.do_zipcode
FROM LOADS AS l, ROUTE AS r1, ROUTE AS r2
WHERE l.pu_zipcode=r1.zipcode
AND l.do_zipcode=r2.zipcode
AND r1.route_order<r2.route_order
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Closed 8 years ago.
This question appears to be off-topic because it lacks sufficient information to diagnose the problem. Describe your problem in more detail or include a minimal example in the question itself.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Improve this question
Using this query I get my data which I want.
select *
from tbl_project
join tbl_project_detail on tbl_project_detail.project_id = tbl_project.id
I need to know how I can use this SQL in Linq-to-SQL:
select SUM(pd.no_vacancy) as Number
from tbl_project p
join tbl_project_detail pd on pd.project_id = p.id
where p.id='1'
I also try it but it doesn't work.
var result = (from p in db.tbl_projects
join c in db.tbl_project_details on p.id equals c.project_id
where c.project_id == type
select new { c.no_vacancy }).Sum();
Please help me.. I am stuck :(
I think this might be help you:
from p in tbl_project
join pd in tbl_project_detail on project_id equals p.id
where p.id=1
select new
{
sum(pd => pd.no_vacancy)
};
At Last I Solve My Problem By Using This
var result = (from p in db.tbl_projects
join
c in db.tbl_project_details on p.id equals c.project_id
where c.project_id == type
select (int)c.no_vacancy ).Sum();
Thank You Everyone For Helping Me.. :)
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
I have a database with products.
I need to add to name of products some string.
Example:
product name "abc1", "abc2", "abc3"
new products name: "Super abc1", "Super abc2", "Super abc3"
Use MySQL's concat().
If you want to update :
update tablename set column=concat('Super ', column);
You can even add a where clause .
update player
set productName= concat("super ",productName)
You need to use CONCAT function
SELECT CONCAT('Super ',columnWithABc) from tab