I
I
Ivan Petrovsky2014-04-13 00:30:56
SQL
Ivan Petrovsky, 2014-04-13 00:30:56

How to create a complex SQL query using a panel?

From words to deeds

SELECT `lab`.`name_lab` FROM lab
LEFT OUTER JOIN `u980745546_db`.`tab` ON `lab`.`id` = `tab`.`id_labr` 
LEFT JOIN `u980745546_db`.`student` ON `tab`.`id_stud` = `student`.`id` 
 WHERE(( `tab`.`id_rez` <> '1') AND ( `student` .`id` = '1'))

This request is used in the php code, it works, but it gives out a little not what is needed.
a1d63501932b48ec92f87ab63254bf1b.jpg
the figure shows the data schema of the tables, it is required to display all the values ​​of the lab table in with the following conditions: it is required to filter out those records that were entered in the tab table with a value not equal to 1 (only 2 values ​​'1' and '2' can be added to the id_rez cell) and these values ​​are added by a user with a specific id, respectively, id_student is also taken into account, the presented query displays a list of the name_lab fields entered in the tab table with a value not equal to 1, and I need to display all the values ​​from the lab table. How to solve the current problem?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
svd71, 2014-04-13
@svd71

select * from lab l,
  left join tab t on t.id_labr = l.id
  left join student s on s.id = t.id_stud
where 
  t.id_rez > 1

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question