J
J
John Freeman2017-09-19 15:14:19
MySQL
John Freeman, 2017-09-19 15:14:19

How to make a selection from a MySQL database?

There is a main table, 6911 records in it,
wrote the following SQL query:

select a.id as id, a.added_date, a.updated_date, a.codename, a.title, a.tech_title, a.category, f.name as family, d.name as developer, a.os, a.domain, a.FULL_URL, a.publicly_called, a.has_image, a.Available_for_PPC, a.PPC_Risk, a.Is_in_blogs, a.Publish_in_Blog, a.Publish_in_Feed, a.IS_IN_SOFT, a.Has_Tech_Info, u.nick as assigned_to, s.name as status, a.domain_popularity, a.adwords_activity, a.lp, a.seo, a.partners, a.Software_Scan, a.Software_Fix, a.tickets, a.Youtube_URL, a.SEVERITY, a.Image_URL
from artpost_table as a
join developer as d on a.developer = d.id
join family as f on a.family = f.id
join users as u on a.assigned_to = u.id
join status as s on a.status = s.id

in the table artpost_table columns:
developer refers to the developer table to the id column
family refers to the family table to the id column
assigned_to refers to the users table to the id column
status refers to the status table to the id column
so, with this query I get only 349 records! Attention question:
Why am I getting 349 entries and not 6911??
if I make a request , I get all 6911 records, and instead of the names in the developer, family, assigned_to, status columns, I get only id (name IDs) Please help! UPD: Thanks LEFT JOIN helped! another question: if I have entries in the same table in the category column: 1,3,6,89,10
SELECT * FROM `artpost_table` WHERE 1
These numbers are responsible for the IDs of the Category table, how can I display names instead of IDs in one query??
f013b2fe01e04456a54d816204455790.png
did like this:
SELECT a.id as id, a.added_date, a.updated_date, a.codename, a.title, a.tech_title, c.name as category, f.name as family, d.name as developer, a.os, a.domain, a.FULL_URL, a.publicly_called, a.has_image, a.Available_for_PPC, a.PPC_Risk, a.Is_in_blogs, a.Publish_in_Blog, a.Publish_in_Feed, a.IS_IN_SOFT, a.Has_Tech_Info, u.nick as assigned_to, s.name as status, a.domain_popularity, a.adwords_activity, a.lp, a.seo, a.partners, a.Software_Scan, a.Software_Fix, a.tickets, a.Youtube_URL, a.SEVERITY, a.Image_URL
FROM artpost_table as a
LEFT JOIN developer as d on a.developer = d.id
LEFT JOIN family as f on a.family = f.id
LEFT JOIN users as u on a.assigned_to = u.id
LEFT JOIN status as s on a.status = s.id
LEFT JOIN category as c on a.category = c.id

output like this:
1a8bc8c40b4b4e6885266e4026ec523b.png
as I understand it, only the first id in the list was used, but I need the type name instead of the id like this: 1,3,4,2 -> cat1,cat3,cat4,cat2
UPD2:
thanks everyone =) solved my last one question with find_in_set()

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Denis Holub, 2017-09-19
@AsviS

Instead of JOIN , write LEFT JOIN and there will be all records.
Not all fields are filled in / have a match in other tables. Therefore, only records with full matches are shown, of which there are 349.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question