My INNER JOIN SQL command yields no results - mysql

I try to make a query using the INNER JOIN command and it executes successfully but it yields no results.
Here is the SQL code I am using:
SELECT * FROM `departament` INNER JOIN `fakultet`
ON "departament.#ID_Fakultet"="fakultet.ID_Fakultet"
And here are the tables
the departament table:
the fakultet table

if you write in double (" ") or single (' ') quotes it will take as string.
SELECT * FROM `departament` INNER JOIN `fakultet`
ON departament.`#ID_Fakultet`=fakultet.`ID_Fakultet`
can you run this query?

Related

Full join multiple queries

I am trying to full join several queries, two will full join, the other won't. It gives error of
invalid use of on clause
Is there a comma or semicolon to be used when trying to full join queries?
select * from
(query1) query1
full join (query2) query2
on query1.x = query2.x; does not join thereafter
full join (query3) query3
on query1.x = query3.x;

mysql string group_concat giving me an error

i'm getting an error here when i try this sql ...
SELECT customers.customers_first_name GROUP_CONCAT(customers_groups.customers_hash SEPARATOR '')
FROM customers INNER JOIN customers_groups ON (customers.hash = customers_groups.customers_hash)
GROUP BY customers.customers_entry_date
CUSTOMERS DATABASE
`customers_id`,
`customers_first_name`,
`customers_surname`,
`customers_telephone`,
`customers_email`,
`customers_telephone_active`,
`customers_email_active`,
`client_type`,
`customers_hash`,
`customers_entry_date`
CUSTOMERS_GROUPS
`groups_hash`
`customers_hash
Ideally, you should post the error message with the question but check below solution.
SELECT customers.customers_first_name, GROUP_CONCAT(customers_groups.customers_hash SEPARATOR '')
FROM customers INNER JOIN customers_groups ON (customers.hash = customers_groups.customers_hash)
GROUP BY customers.customers_entry_date
SELECT customers.customers_first_name ,
"," was missing in the select statement before GROUP_CONCAT

Get sequel generated sql to generate field names without backticks

I have the following query written in SQL:
Select *
From npt_articles
Inner Join npt_authors
Inner Join users
Inner Join npt_teams
Where npt_teams.id In (1)
and the following sql generated by the sequel gem:
SELECT *
FROM `npt_articles`
INNER JOIN `npt_authors`
INNER JOIN `users`
INNER JOIN `npt_teams`
WHERE ('npt_teams.id' IN (1))
The first returns results, the second one doesn't, if I remove the back-ticks then the second then it generates the same result as the first.
This is the code that generates the second sql:
team_articles = user.npt_teams.to_a.inject({}) {|arts,team|
arts.merge({ team.name =>
NptArticle.join(:npt_authors).join(:users).join(:npt_teams).where('npt_teams.id' => [team.id]).to_a.uniq})
}
How do I get the query generated without backticks?
You should try something like this:
.where(:npt_teams__id => [team.id])

mysql query to perform multiple inner joins on the same table

I need to perform multiple joins on the same table. Below is my query.
When I execute following query , it gives me duplicate record for a single column.
Can anyone tell me where am I going wrong?
$result=mysql_query("SELECT DISTINCT *,CONCAT(phno, ' ', vnumber) AS source,CONCAT(phno, ' ', vnumber) AS destination FROM gcm_users as gu
INNER JOIN message_Log as ml1 ON gu.imei= ml1.Source_ID
INNER JOIN message_Log as ml2 ON gu.imei= ml2.Destination_ID
WHERE gu.id={$_SESSION['uid']}");
You can replace 2 joins with one
INNER JOIN message_Log as ml1 ON gu.imei= ml1.Source_ID
OR gu.imei= ml2.Destination_ID

triple nested mysql selects returns no results when it should

This SQL Query
(SELECT * FROM OperatorRoster as roster
INNER JOIN ( SELECT *, count(*) as activeSlots FROM Connectors
group by (operator)) as connectors
ON connectors.operator = roster.operator)
Workes fine and return all the values that i need, but i need to use the restult in a new query
but if i try to use it:
SELECT * FROM (SELECT * FROM OperatorRoster as roster
INNER JOIN ( SELECT *, count(*) as activeSlots FROM Connectors
group by (operator)) as connectors
ON connectors.operator = roster.operator) as q
It returs nothing.
how can i query this subquery?
you are missing an ON clause of the main join .
on q.___= Operators.___
Since you are using an inner join, are you sure that there exist rows where
connectors.operator=roster.operator
if there are no rows that match that requirement then your query shouldn't return any rows
Turns out that since I did a join on operators but select all fields,
(SELECT * FROM OperatorRoster as roster
INNER JOIN ( SELECT *, count(*) as activeSlots FROM Connectors
group by operator) as connectors
ON connectors.operator = roster.operator)
It returns two fields with the same name "connectors.operator" and "roster.operator", and since the last select cant inherit the scoop, it conflicts.
No clued why it did not return an error but I fixed it by only selecting one operator field.