php - Get CSV from query which involves multiple tables -
i'm trying make query extract elements 2 tables, linked via table.
so have 3 tables:
authors - id, name, book category - id, name, description category-author - id, idauthor, idcategory
now want make query make following output:
row: authors.id, authors.name, authors.book, category.name
i don't know category's linked using 2 tables only, need use last one, category-author table. id's of both author , category linked via table.
i got following query:
select authors.id, authors.name, authors.book, category.name category, author left join select ??
i'm stuck @ remaining part of query.
also when have query, can extract csv phpmyadmin?
you can related information different tables using table joins. relations between tables should specified using foreign keys (i.e. column idcategory
category-author
presumably foreign key refers primary key column category.id
). in join clause, merely specify tables joined , on column:
select table1.col1, table2.col2 table1 join table2 on table1.pkcol = table2.fkcol
this means can't specify select
or from
clauses within join clause. columns wish select joined tables specified in initial select
statement, , specify 1 table in from
clause, subsequently perform table joins. in case, think should started:
select authors.id, authors.name, authors.book, category.name category left join category-author on category-author.idcategory = category.id left join authors on authors.id = category-author.idauthor
i'm not sure how familiar foreign keys, primary keys , table joins, won't elaborate more on this. think specifying multiple tables in from
clause bad practice, if database system still supports (related question).
from on, can export results within phpmyadmin, there export button every table overview, including query results.
Comments
Post a Comment