0

-SOLUTION-

SELECT Table1.unvan, Table2.sayi FROM 
(SELECT id , unvan FROM unvan WHERE id IN 
(SELECT unvani FROM personel WHERE gorev_yeri IN 
(SELECT id FROM gorev_yeri WHERE il_id="34") ) ) AS Table1 
JOIN
( SELECT unvani as id , count(*) AS sayi FROM personel WHERE gorev_yeri IN (SELECT id FROM gorev_yeri WHERE il_id="34") GROUP BY unvani ) AS Table2 
ON Table1.id = Table2.id

-EDIT-

When I use join with as I get this error : #1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'AS table1

I have 2 query and I want join them.

It is first.

SELECT id
     , unvan 
  FROM unvan 
 WHERE id IN (SELECT unvani 
                FROM personel 
               WHERE gorev_yeri IN (SELECT id 
                                      FROM gorev_yeri 
                                     WHERE il_id="34")
              )

It is second one.

SELECT unvani as id
     , count(*) AS sayi 
 FROM personel 
WHERE gorev_yeri IN (SELECT id 
                       FROM gorev_yeri 
                        WHERE il_id="34") GROUP BY unvani

I need this:

unvan|sayi

--------|----

4
  • 1
    You really don't like the word JOIN, do you? Commented Jun 7, 2017 at 11:19
  • See: Why should I provide an MCVE for what seems to me to be a very simple SQL query? Commented Jun 7, 2017 at 11:20
  • Add some sample results from the two queries, and show us the combined result. (Well formatted text, please.) Commented Jun 7, 2017 at 11:22
  • Thanks for underestimate me about join. When I use join i get error like this : #1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'table1. Commented Jun 7, 2017 at 11:28

2 Answers 2

2

Based from error provided

It should be like this:

SELECT `Table1`.unvan, `Table2`.id
FROM
(
    SELECT id
    , unvan 
   FROM unvan 
   WHERE id IN (SELECT unvani 
            FROM personel 
           WHERE gorev_yeri IN (SELECT id 
                                  FROM gorev_yeri 
                                 WHERE il_id="34")
          )
) AS `Table1`

JOIN

(
SELECT unvani as id
 , count(*) AS sayi 
 FROM personel 
 WHERE gorev_yeri IN (SELECT id 
                   FROM gorev_yeri 
                    WHERE il_id="34") GROUP BY unvani
) AS `Table2`

ON `Table1`.id = `Table2`.id
Sign up to request clarification or add additional context in comments.

Comments

1

(SELECT id , unvan FROM unvan WHERE id IN (SELECT unvani FROM personel WHERE gorev_yeri IN (SELECT id FROM gorev_yeri WHERE il_id="34") ) )table1

join

( SELECT unvani as id, count(*) AS sayi FROM personel WHERE gorev_yeri IN (SELECT id FROM gorev_yeri WHERE il_id="34") GROUP BY unvani )table2

on table1.id=table2.id;

4 Comments

When I use join i get error like this : #1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'table1.
Add SELECT * FROM first of all. And, perhaps you need to do as table1.
Yeah, sorry I forgot, Add Select * from
Same error again : #1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'AS table1

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.